ramlicious Blogs by Tina & Prabhu

August 9, 2010

Row Values as Character-separated List

Filed under: SQL Server — Prabhuram @ 7:02 am

Ever searched for an easiest way to create a CSV from a row of values. Here it is:

DECLARE @Categories varchar(max)
DECLARE @Character char(1)
Select @Character = ',' –separator
Select @Categories = Coalesce(@Categories + @Character, '') + CategoryName from Northwind.dbo.Categories
SELECT @Categories

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress