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 2005 Forums
 Transact-SQL (2005)
 combining several rows into one comma separated

Author  Topic 

stonebreaker
Yak Posting Veteran

92 Posts

Posted - 2008-10-31 : 15:29:03
I was wondering if there is any way to combine the results from several rows into one, with the values from the result set separated by commas.

I know how to do it using cursors, but cursors are too slow. Instead of a result set that looked like this:

Building Account
A 12
A 33
A 4
B 43
B 6
etc...

I'd like to get a result set that looked something like this:

Building Account_List
A 12, 33, 4
B 43, 6
C 954, 3, 332

Thanks in advance for your help.

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-10-31 : 15:45:01
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62643
"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-10-31 : 15:47:14
Here's a great example by peso.

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


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

stonebreaker
Yak Posting Veteran

92 Posts

Posted - 2008-10-31 : 16:23:00
Thanks for the quick responses - especially on a Friday afternoon!
Go to Top of Page
   

- Advertisement -