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 2005 Forums
 Other SQL Server Topics (2005)
 Combine row results based on multiple criteria
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

poison88
Starting Member

USA
1 Posts

Posted - 06/15/2012 :  13:00:37  Show Profile  Reply with Quote
I have a query that retrieves a large result set—200,000+ records—with correct data but separated into multiple rows. I need to combine some of these rows together by 2 field criteria. This is an example of what I have and what I need:
Manufactured_Item Operation Task Text
86252-01 10 250 First part of text
86252-01 10 250 and the 2nd part of text
86252-01 10 250 then remaining text.
86252-01 20 400 NULL
86252-01 30 250 Text for Operation 30

Based on the Manufactured_Item number and Operation—if the same—I need to have a unique row with the text combined (concatenated); I need it to look like this:
Manufactured_Item Operation Task Text
86252-01 10 250 First part of text and the 2nd part of text then remaining text.
86252-01 20 400 NULL
86252-01 30 250 Text for Operation 30

How can I accomplish this through a Management Studio Query?

Thank you very much!


Poison88

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 06/17/2012 :  11:58:59  Show Profile  Reply with Quote

SELECT Manufactured_Item,
Operation,
Task,
STUFF((SELECT '' + FROM Table 
WHERE Manufactured_Item = t.Manufactured_Item 
AND Operation = t.Operation 
AND Task = t.Task 
FOR XML PATH('')),1,1,'') AS List
FROM (SELECT DISTINCT Manufactured_Item,Operation,Task FROM Table) t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


Edited by - visakh16 on 06/17/2012 11:59:50
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.12 seconds. Powered By: Snitz Forums 2000