SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 [RESOLVED] merge 2 or more records
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

HenryFulmer
Posting Yak Master

USA
110 Posts

Posted - 10/14/2013 :  18:21:21  Show Profile  Reply with Quote
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; XCP

How would I approach this?

Edited by - HenryFulmer on 10/15/2013 10:16:39

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/15/2013 :  00:49:59  Show Profile  Reply with Quote

SELECT t.No,
STUFF((SELECT ';' + [Type] FROM Table WHERE [No] = t.[No] FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT [No] FROM Table)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/15/2013 :  00:50:00  Show Profile  Reply with Quote

SELECT t.No,
STUFF((SELECT ';' + [Type] FROM Table WHERE [No] = t.[No] FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT [No] FROM Table)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
169 Posts

Posted - 10/15/2013 :  01:00:26  Show Profile  Reply with Quote
SELECT [No] +' | ' + STUFF((SELECT ' ; ' + [Type] FROM #T WHERE [No] = t.[No] FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT [No] FROM #T)t

veeranjaneyulu
Go to Top of Page

HenryFulmer
Posting Yak Master

USA
110 Posts

Posted - 10/15/2013 :  10:16:12  Show Profile  Reply with Quote
perfect - thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.08 seconds. Powered By: Snitz Forums 2000