Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 Article Discussion
 Building comma separated string for query result

Author  Topic 

sawantaartid
Starting Member

1 Post

Posted - 2006-01-16 : 05:15:52
I need to build a comma separated string of the multiple rows returned out of query result. Select is only on one column. Below is the query I wrote for the same

Declare @Description varchar(100)
set @Description = ''
select @Description = @Description + [Description] FROM ud_LookupMGR_Data where dataid in (81,82,83,84)
select @Description

This result returns only the value of 1st row.

Pls help

Thanks

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-01-16 : 05:24:35
try this

Declare @Description varchar(4000)
select @Description = coalesce(@Description + ',' , Description ) + Description
FROM ud_LookupMGR_Data where dataid in (81,82,83,84)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-16 : 06:37:45
Also refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

muralin
Starting Member

1 Post

Posted - 2008-11-18 : 08:25:15
Declare @Description varchar(4000)
select @Description = coalesce(@Description + ',' , '') + Description
FROM ud_LookupMGR_Data where dataid in (81,82,83,84)

it is working
Go to Top of Page
   

- Advertisement -