Thursday 19 May 2011

Column values as a single string - MS Sql Server

There are situations where you need the resultant values of a single column to be displayed/processed as a single string. So here goes the query:

DECLARE @Str VARCHAR(MAX)
SELECT @Str = COALESCE(@Str+',' ,'') + CONVERT(varchar,Column1) FROM MyTable
SELECT @Str

No comments: