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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to merge rows?

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2012-03-28 : 18:07:19
Hello,

I need to consolidate the rows below by ID, that is, merge the rows for each unique id into one row.

ID Fld1 Fld2 Fld3
1 null val1 null
1 valx null valy
2 null valn valp
3 null null valx
3 null valy null
3 valn null null

result should be:

ID Fld1 Fld2 Fld3
1 valx val1 valy
2 null valn valp
3 valn valy valx

Thank for your help!

--PhB

phrankbooth
Posting Yak Master

162 Posts

Posted - 2012-03-28 : 18:21:44
oh found it: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=99576

--PhB
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-28 : 18:33:15
Well, that hack is all well and good..but what if you had

ID Fld1 Fld2 Fld3
1 null val1 null
1 valz null valx
1 null val2 null
1 valx null valy

What then?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -