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.
Author |
Topic |
reading2009
Starting Member
22 Posts |
Posted - 2013-01-08 : 21:08:22
|
my data:col1 col2name1 abcname1 defname1 xyzname2 abcname2 ghyname3 xyzname3 hyudesired outputcol1 col2name1 abc,def,xyzname2 abc,ghyname3 xyz,hyuhow can i get my desired output through a sql query?thank you. |
|
reading2009
Starting Member
22 Posts |
Posted - 2013-01-08 : 21:22:28
|
any response please |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-08 : 23:25:02
|
[code]SELECT t.col1,STUFF((SELECT ',' + col2 FROM table WHERE col1 = t.col1 FOR XML PATH('')),1,1,'')FROM (SELECT DISTINCT col1 FROM table) t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2013-01-09 : 21:36:19
|
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." |
|
|
|
|
|
|
|