MS Access 查询用列 header 文本填充单元格,其中该列的值 = "Yes"
MS Acces query to populate cell with column header text where that column's value = "Yes"
我有一个 table 看起来像这样:
Patient Name
Injury A
Injury B
Bob
Yes
Yes
Mary
Yes
No
我想编写一个查询来填充一个列,连接伤害 header 文本,用逗号分隔,其中一个伤害列中有一个“是”,如下所示.
Patient Name
Injury A
Injury B
All Injuries
Bob
Yes
Yes
Injury A, Injury B
Mary
Yes
No
Injury A
感谢任何帮助。
使用 IIf() 表达式。
SELECT Table1.PatientName, Table1.InjuryA, Table1.InjuryB,
IIf([InjuryA]="Yes","InjuryA",Null) & IIf([InjuryA]="Yes" And [InjuryB]="Yes",", ",Null) & IIf([InjuryB]="Yes","InjuryB",Null) AS AllInjuries
FROM Table1;
我有一个 table 看起来像这样:
Patient Name | Injury A | Injury B |
---|---|---|
Bob | Yes | Yes |
Mary | Yes | No |
我想编写一个查询来填充一个列,连接伤害 header 文本,用逗号分隔,其中一个伤害列中有一个“是”,如下所示.
Patient Name | Injury A | Injury B | All Injuries |
---|---|---|---|
Bob | Yes | Yes | Injury A, Injury B |
Mary | Yes | No | Injury A |
感谢任何帮助。
使用 IIf() 表达式。
SELECT Table1.PatientName, Table1.InjuryA, Table1.InjuryB,
IIf([InjuryA]="Yes","InjuryA",Null) & IIf([InjuryA]="Yes" And [InjuryB]="Yes",", ",Null) & IIf([InjuryB]="Yes","InjuryB",Null) AS AllInjuries
FROM Table1;