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
 Using COALESCE to build a comma-delimited string

Author  Topic 

billsox
Yak Posting Veteran

74 Posts

Posted - 2003-02-16 : 08:15:29

Hi folks --

I love the SQL Team article on using COALESCE to build comma-delimited strings. Very useful in my work. But I'm running into a situation where I want to use this technique but can't seem to figure out how. Basically, I have a table that looks like this:


Field1 Field2
====== ======
A 1
A 2
A 3
B 1
B 2
B 3
B 4



And I want to be able to create a SELECT statement whose results look like this:


Field1 Field2
====== ======
A 1, 2, 3
B 1, 2, 3, 4



Any ideas on how I can accomplish this?

Thanks in advance.

Bill

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-02-16 : 08:18:28
There's one or two other articles on how to extend the functionality:

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

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-02-16 : 10:06:36
Look at Byrmol's post for a neat function idea that's easy to use, efficient, and works in any SELECT statement -- as long as you have SQL 2000:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=19647

- Jeff
Go to Top of Page
   

- Advertisement -