Getiing Query Result as Comma Separated Value




Getting the sql query output to comma separated value. For example, In the below query instaed of getting values into row by row, the below query will give the result in 1 row as a comma separated.



declare @name varchar(500)
set @name=''
select @name = coalesce(@name+lastname +',','') from employees where employeeid in (1,2,3,4,5);
select substring(@name,1,len(@name)-1)



Related Articles

How to get rows into comma separated values column in sql

How to get rows into comma separated values column in sql. Fetching rows values into comma separated column value is required lots of time in our projects. So I tried to achieve this and lastly found one solution. Use this to get all row values into one single column value with comma separation.

Split Comma separated values into Columns

In this article, I explain about how to split a string with delimiter into list of rows. De limiter can be comma or plus our requirement is to convert a single row of a table into multiple rows based on number of delimiter.

More articles: Comma separated value

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: