Please start any new threads on our new site at 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
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Mutiple row value in one cell with comma seperated
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

22 Posts

Posted - 01/08/2013 :  21:08:22  Show Profile  Reply with Quote
my data:
col1 col2
name1 abc
name1 def
name1 xyz
name2 abc
name2 ghy
name3 xyz
name3 hyu

desired output
col1 col2
name1 abc,def,xyz
name2 abc,ghy
name3 xyz,hyu

how can i get my desired output through a sql query?
thank you.

Starting Member

22 Posts

Posted - 01/08/2013 :  21:22:28  Show Profile  Reply with Quote
any response please
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/08/2013 :  23:25:02  Show Profile  Reply with Quote

SELECT t.col1,
STUFF((SELECT ',' + col2 FROM table WHERE col1 = t.col1 FOR XML PATH('')),1,1,'')

SQL Server MVP

Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 01/09/2013 :  21:36:19  Show Profile  Reply with Quote
Originally posted by reading2009

any response please

Lordy you're impatient. This is a forum... not your personal help button.

--Jeff Moden
RBAR is pronounced "ree-bar" and is a "Modenism" for "Row By Agonizing Row".

First step towards the paradigm shift of writing Set Based code:
"Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

When writing schedules, keep the following in mind:
"If you want it real bad, that's the way you'll likely get it."
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.03 seconds. Powered By: Snitz Forums 2000