Skip to content

How to get column values as comma separated string in SQL

Ever wondered that how to get a comma (pipe or whatever) separated result for a column in a table in SQL Server?

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,''))

Update: Elina Blank suggested an alternative to the approach above on my CodeProject Tip. Thanks Elina 🙂

Have a look at alternative here at CodeProject.

Published inUncategorized

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *