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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Multiple comma delimited lists

Author  Topic 

DBCowboy
Starting Member

26 Posts

Posted - 2003-02-28 : 12:11:26
Okay, I know the technique from http://www.sqlteam.com/item.asp?ItemID=2368 for creating a comma delimited list.

However, I need to create a comma delimited list based off of another parameter in the table.

In other words, I have the data like so:
Name1 | Value1
Name1 | Value2
Name2 | Value3
Name2 | Value4

And I need to transform the results to:
Name1 | Value1,Value2
Name2 | Value3,Value4

In a table or table variable. There may be more than two names, and I can't know in advance how many there will be of either names, or values, since this is going into a stored procedure that will take input.

Is there any way to do this without using a cursor? All I've been able to come up with is a list of all values for each name, or a method using a cursor to parse each name's value separately.

Hopefully someone's got a solution for me!

Thanks!
Jaysen

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-02-28 : 12:25:59
Yep. If you search SQL Team for "CSV":

http://www.sqlteam.com/SearchResults.asp?SearchTerms=csv

You'll find this:

http://www.sqlteam.com/item.asp?ItemID=11021

Go to Top of Page

DBCowboy
Starting Member

26 Posts

Posted - 2003-02-28 : 12:42:09
Thanks, was searching for "comma separated value" and didn't find it.

Go to Top of Page
   

- Advertisement -