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 |
|
chopstix21
Starting Member
1 Post |
Posted - 2012-05-23 : 09:46:58
|
| i need to concatenate x values which are grouped by id, ordering them by y column from subquery.Subquery looks like thisid x y1 1 11 2 31 3 22 1 null2 2 13 1 13 2 24 1 null4 2 null final result should look likeid result 1 1,3,22 23 1,2 4 null |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-23 : 14:44:37
|
| [code]SELECT id,STUFF((SELECT ',' + CAST(x AS varchar(10)) FROM table WHERE id = t.id AND y IS NOT NULL ORDER BY y FOR XML PATH('')),1,1,'')FROM (SELECT DISTINCT id FROM table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|