Get rows of table as a Single column with Comma in SQL

Hai All,
              I came in a situation to get the result of tables in in raw form to a column form with comma separated

tbl_Sample


ID

Data

1abc
2pqr
3xyz


Suppose to get the data from tbl_Sample  as


Output

abc,pqr,xyz
to achieve that we can use the following query

SELECT  STUFF((SELECT ', ' + RTRIM(Data) FROM tbl_Sample FOR XML PATH('')),1,1,'') AS 'Output'
 
Hope this may help you in some situations


Thanks
SHARE

Gibin Francis

Hi. I’m Software Engineer in India. I’m Web Developer, Creative Coder, Web Designer, logo Designer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Designer. Inspired to make things looks better and Do the this in the best way.

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment