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 |
shankarvalleru
Starting Member
1 Post |
Posted - 2010-12-02 : 12:53:34
|
Hi,I have a table like thisID TERM CLASS---------------------------304 20103 EE2156 20102 CS3167 20101 MC1167 20101 SE3As you can see, for the ID 167, there are two different values 'MC1' & 'SE3' under CLASS column. I want to create a query which coalesces'MC1' & 'SE3' into one field, I would like the resulting table to be likeID TERM CLASS---------------------------304 20103 EE2156 20102 CS3167 20101 MC1,SE3Any help?SHankar |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-03 : 11:08:29
|
Try:-- Show the expected outputSELECT DISTINCT s1.ID,S1.Term, STUFF((SELECT ',' + s2.Class FROM MyTable AS s2 WHERE s2.ID = s1.ID FOR XML PATH('')), 1, 1, '') AS ClassFROM MyTable AS s1ORDER BY s1.IDRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
|
|