答案 0 :(得分:0)
从您显示的示例中,只需在DISTINCT
子句中添加逗号,然后将STUFF
函数start
参数更改为1:
select distinct t1.FieldA,
STUFF((SELECT distinct ',' + t2.FieldB
from yourtable t2
where t1.FieldA = t2.FieldA
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'') data
from yourtable t1;