如何将多个字段查询为一个

How do I query multiple fields into one

我正在尝试创建一个查询,returns 每个逗号分隔值到一列中

TEXT
A1,A2,A3
X,D3,PP
FF
DF(a),R

这是我试过的。 下面的脚本将每个逗号分隔值(永远不会超过 3)提取到 3 列中,并尝试 UNION THEM

SELECT IIf(InStr([A],",")='0',[A],Left([A],InStr([A],",")-1))  FROM Tbl
UNION ALL
SELECT  IIf(InStr([A],",")='0','',Mid([A],InStr([A],",")+'1',Len([A])-InStr(Len(IIf(InStr([A],",")='0',[A],Left([A],InStr([A],",")-1)))+'2',[A],","))) FROM Tbl
UNION ALL
SELECT  IIf(InStr(Len(IIf(InStr([A],",")='0',[A],Left([A],InStr([A],",")-1)))+'2',[A],",")='0','',Mid([A],InStr(Len(IIf(InStr([A],",")='0',[A],Left([A],InStr([A],",")-1)))+'2',[A],",")+1)) FROM Tbl;

当运行查询时出现错误Data type mismatch in criteria expression 公式在以下查询中工作正常

SELECT [Tbl].A, 
IIf(InStr([A],",")='0',[A],Left([A],InStr([A],",")-1)) AS a, 
IIf(InStr([A],",")='0','',Mid([A],InStr([A],",")+'1',Len([A])-InStr(Len([a])+'2',[A],","))) AS b, 
IIf(InStr(Len([a])+'2',[A],",")='0','',Mid([A],InStr(Len([a])+'2',[A],",")+1)) AS c
FROM Tbl;

期望的结果应该是:

TEXT
A1
A2
A3
X
D3
PP
FF
DF(a)
R

数字不是文本,因此请删除引号:

SELECT IIf(InStr([A],",")=0,[A],Left([A],InStr([A],",")-1)) 
FROM Tbl
UNION ALL
SELECT IIf(InStr([A],",")=0,'',Mid([A],InStr([A],",")+1,Len([A])-InStr(Len(IIf(InStr([A],",")=0,[A],Left([A],InStr([A],",")-1)))+2,[A],","))) 
FROM Tbl
UNION ALL
SELECT IIf(InStr(Len(IIf(InStr([A],",")=0,[A],Left([A],InStr([A],",")-1)))+2,[A],",")=0,'',Mid([A],InStr(Len(IIf(InStr([A],",")=0,[A],Left([A],InStr([A],",")-1)))+2,[A],",")+1)) 
FROM Tbl;