下面的代码(我从这里得到的)在将多个用逗号分隔的字段合并在一起方面做得很好。
select player,
stuff((SELECT distinct ', ' + cast(score as varchar(10))
FROM yourtable t2
where t2.player = t1.player
FOR XML PATH('')),1,1,'')
from yourtable t1
group by player
我需要用回车换行替换逗号。我尝试了下面的代码,但它开始用这些字符分隔条目:“#x0D;”
select player,
stuff((SELECT distinct CHAR(13)+CHAR(10) + cast(score as varchar(10))
FROM yourtable t2
where t2.player = t1.player
FOR XML PATH('')),1,1,'')
from yourtable t1
group by player
我怀疑问题出在“FOR XML PATH('')),1,1,''”,但我不知道要输入什么值。
任何帮助将不胜感激。
谢谢!