SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Combining multiple rows into one row


Combining multiple rows into one row

Author
Message
vnj
vnj
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 52
I have a table in sql server which has more than 100 columns with rows like this

eg:
IDKEY INTKey HRI STRID1 CID SEG T L TMP
71073287 877699 9839 131025521 84046D 2 0 0 0
71072766 877699 9839 131025521 84046D 2 0.61 0.2 1050.24
71072767 877699 9839 131025521 84046D 3 0 0.26 1059.71
71073288 877699 9839 131025521 84046D 3 0.81 0 0
71073288 877699 9839 131025521 84046D 3 0 0 0
71072566 877699 9839 131025521 84046D 4 0 0.33 0
71072768 877699 9839 131025521 84046D 4 1.02 0
71073870 877699 9839 131025521 84046D 4 0 0 1062.8

I need to combine the rows with same CID and SEG into one row and delete the others.
eg
IDKEY INTKey HRI STRID1 CID SEG T L TMP
71073287 877699 9839 131025521 84046D 2 0.61 0.2 1050.24
71072767 877699 9839 131025521 84046D 3 0.81 0.26 1059.71
71072566 877699 9839 131025521 84046D 4 1.02 0.33 1062.8


How can this be done??
J Livingston SQL
J Livingston SQL
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5481 Visits: 35448
will GROUP BY and MAX do it to get the new rows?

edit...whats the business rule for IDKEY...??

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search