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 |
HenryFulmer
Posting Yak Master
110 Posts |
Posted - 2013-10-14 : 18:21:21
|
I have a table with multiple records.No | Type | ZA123 | TCP | ZA123 | XCP | GT456 | POI | GT456 | HYR |I would need a result set that combines the Type values, like:ZA123 | TCP; XCPHow would I approach this? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-15 : 00:49:59
|
[code]SELECT t.No,STUFF((SELECT ';' + [Type] FROM Table WHERE [No] = t.[No] FOR XML PATH('')),1,1,'')FROM (SELECT DISTINCT [No] FROM Table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-15 : 00:50:00
|
[code]SELECT t.No,STUFF((SELECT ';' + [Type] FROM Table WHERE [No] = t.[No] FOR XML PATH('')),1,1,'')FROM (SELECT DISTINCT [No] FROM Table)t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
VeeranjaneyuluAnnapureddy
Posting Yak Master
169 Posts |
Posted - 2013-10-15 : 01:00:26
|
SELECT [No] +' | ' + STUFF((SELECT ' ; ' + [Type] FROM #T WHERE [No] = t.[No] FOR XML PATH('')),1,1,'')FROM (SELECT DISTINCT [No] FROM #T)tveeranjaneyulu |
|
|
HenryFulmer
Posting Yak Master
110 Posts |
Posted - 2013-10-15 : 10:16:12
|
perfect - thanks |
|
|
|
|
|