连接字符串 [英] concatenating string
本文介绍了连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SQL sever 有没有办法可以把输出写成如下:
Is there a way in SQL sever that can write the output as follow:
select events
from mytable
原始输出
events
--------
123456
894531
985233
829292
920202
392939
299223
期望输出
'123456', '894531','985233','829292','920202','392939','299223'
选择 '' + CustomerID + ','来自 dbo.Customers顾客ID阿尔夫基,ANATR,安东,阿鲁特,伯格斯,
select '' + CustomerID + ',' from dbo.Customers customerid ALFKI, ANATR, ANTON, AROUT, BERGS,
希望看到的结果是顾客ID'ALFKI','ANATR','安东','AROUT','伯格斯',等等...
Would like to see the result as customerid 'ALFKI', 'ANATR', 'ANTON', 'AROUT', 'BERGS', so on...
推荐答案
SELECT
STUFF(
(SELECT
', ' + events
FROM dbo.mytable
FOR XML PATH('')
), 1, 1, '') As concatenated_string
如果您希望将值括在单引号中,请编辑上面的填充.
If you want the values enclosed in single quotes then edit the padding above.
这篇关于连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文