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.

Sorry, the comment form is closed at this time.

Powered by WordPress