Get comma sepatared records from a table

by 9:04 PM 0 comments


Hello friends here i am going to show you how to display the records in a coma separated string from a table..

for example say you have a records like following:

NAME
Ravi
Mahesh
Mohan
Rajesh

and you want to display it as follow..

Ravi,Mahesh,Mohan,Rajesh ....than follow this syntax of query.


DECLARE @listStr VARCHAR(MAX)
SELECT @listStr = COALESCE(@listStr+',','') + Name from Employee 
SELECT @listStr as Names






hope you enjoyed it..!

Ravi Tuvar

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 comments:

Post a Comment