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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Building comma separated string for query result
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sawantaartid
Starting Member

1 Posts

Posted - 01/16/2006 :  05:15:52  Show Profile  Reply with Quote
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

India
394 Posts

Posted - 01/16/2006 :  05:24:35  Show Profile  Reply with Quote
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

India
22864 Posts

Posted - 01/16/2006 :  06:37:45  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
1 Posts

Posted - 11/18/2008 :  08:25:15  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000