Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

Get Column values as comma seperated string

5.00/5 (4 votes)
19 Jan 2010CPOL 17.1K  
Ever wondered that how to get a comma (pipe or whatever) seperated result for a column in a table.The following statement show a simple example you can take as a starting point.Select (Stuff((Select ', ' + FName From Accounts FOR XML PATH('')),1,2,''))
Ever wondered that how to get a comma (pipe or whatever) seperated result for a column in a table.

The following statement show a simple example you can take as a starting point.

Select (Stuff((Select ', ' + FName From Accounts FOR XML PATH('')),1,2,''))

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)