Let say you have a table
Table: FruitBasket ----------------- ID FruitName ------------------ 1 Apple 2 Mango 3 Banana 4 Grapes 5 Orange -------------------
And you want to have them selected as comma separated values in your output paramters. Below is the quickest method
Declare @csvFruits Nvarchar(max)
Select @csvFruits = COALESCE( @csvFruits + ', ','') + FruitName From FruitBasket
Print @csvFruits
Output: Apple,Mango,Banana,Grapes,Orange
You can build a user defined function and reuse the function easily.
COALESCE( @csvFruits + ', ','') is similar to ISNULL() function in SQL , read this article.
http://msdn.microsoft.com/en-us/library/ms190349.aspx
|
No responses found. Be the first to respond and make money from revenue sharing program.
|