Select values from a column into a pipe-delimited row
I have a column with some generic data and I want to present the data in a开发者_如何学Go single, pipe-delimited row. The data:
ColumnA
========
asdfaa
asdf
Desired result:
asdfaa|asdf
SELECT Result = STUFF((SELECT N'|' + ColumnA
FROM dbo.[table]
FOR XML PATH(''),
TYPE).value(N'./text()[1]', N'nvarchar(max)'), 1, 1, N'');
精彩评论