Overblog Follow this blog
Edit post Administration Create my blog
Balavardhan Reddy Narani

Query to get Multiple rows data in Single Line from the Sql Server Database Without Using STUFF Command

March 7 2009 , Written by Balavardhan Published on #SQL Server2005

By the Below Query you will get Multiple rows data in Single Line from the Sql Server Database

select <<Column_name>> as "text()", ',' as "text()" from <
> for xml path('')

Ex : My Table structure

Create Table #temp1(MyID Int)

Insert Into #temp1(1)
Insert Into #temp1(2)
Insert Into #temp1(3)
Insert Into #temp1(4)
Insert Into #temp1(5)

select MyID as "text()", ',' as "text()" from #temp1 for xml path('')



Output
--
1,2,3,4,5

Share this post

Repost 0

Comment on this post