以当前形式查询:
SELECT
sr,
Iif([1]="Null", "", "; 1: "&[1])
& Iif([2]="Null", "", "; 2: "&[2])
& Iif([3]="Null", "", "; 3: "&[3]) AS all_parameters
from (
TRANSFORM first([value])
SELECT [id]
FROM [table]
GROUP BY [id]
PIVOT [value]);
1)我的一张桌子有多对一的关系。
[id] | [values]
1 | v1
1 | v2
2 | v1
2 | v3
我想要的样子:
1 | v1, v2
2 | v1, v3
2)我从交叉表查询开始:
TRANSFORM first([value])
SELECT [id]
FROM [table]
GROUP BY [id]
PIVOT [value];
它返回这样的显示:
[id] | [v1] | [v2] | [v3]
1 | 1 | 2 |
2 | 1 | | 3
它只返回数字,因为值来自下拉选择菜单。
3)我想在丢弃Null的同时将v1,v2和v3值连接在一起,所以我使用的是:MS Access - combine non-null column values into a (column name: column value) text string / field
要创建此文件:
SELECT
sr,
Iif([1] is null, "", "; 1: "&[1])
& Iif([2] is null, "", "; 2: "&[2])
& Iif([3] is null, "", "; 3: "&[3]) AS all_parameters
from (
TRANSFORM first([value])
SELECT [id]
FROM [table]
GROUP BY [id]
PIVOT [value]);
4)当我运行它时,出现突出显示TRANSFORM的语法错误。
如何解决此问题,如何获得要显示的下拉引用?
EDIT ___________________
现在我有:
SELECT
[ID],
Iif([1] is null, "", "; 1: "&[1])
& Iif([2] is null, "", "; 2: "&[2])
& Iif([3] is null, "", "; 3: "&[3]) AS all_parameters
from [query]
它返回:
[id] | [all_parameters]
1 | ;1: ; 2: |
2 | ;1: ; 3: |
答案 0 :(得分:1)
您可能无法做到这一点。尝试将交叉表查询另存为命名查询,并将其用作父查询的源。
请参阅: