| Author |
Topic |
|
subt13
Starting Member
11 Posts |
Posted - 2010-01-07 : 17:16:59
|
| I have a result set in the form of:col1 col2 col31 null null2 null nullnull 10 nullnull 20 nullnull null 30null null 40Any ideas on how to update this result to be:col1 col2 col31 10 302 20 40Thanks! |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-07 : 17:25:12
|
| Is this the result of a SELECT statement? If yes, can you show us that statement. |
 |
|
|
subt13
Starting Member
11 Posts |
Posted - 2010-01-07 : 17:26:46
|
| This is just a dump of the table (select * from table) |
 |
|
|
jcampbell
Starting Member
9 Posts |
Posted - 2010-01-07 : 17:32:29
|
| how do you know that 1 in col1 and 10 in col2 and 30 in col3 belong together?Is there another field on all the rows that can identify a row of data? |
 |
|
|
subt13
Starting Member
11 Posts |
Posted - 2010-01-07 : 17:35:08
|
quote: Originally posted by jcampbell how do you know that 1 in col1 and 10 in col2 and 30 in col3 belong together?Is there another field on all the rows that can identify a row of data?
Sorry for the confusion. Yes.Each pair of rows in this exmaple has a "group" identifier. For example:Col4 would be:112233 |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-07 : 17:38:56
|
| That doesn't help...Did you mean col4 would be 121212 |
 |
|
|
subt13
Starting Member
11 Posts |
Posted - 2010-01-07 : 17:41:43
|
quote: Originally posted by vijayisonly That doesn't help...Did you mean col4 would be 121212
No, I didn't. |
 |
|
|
subt13
Starting Member
11 Posts |
Posted - 2010-01-07 : 17:46:06
|
| If this is impossible to do without one column (or group of columns) that is/are unique for each row. Then I can add that to the table. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-07 : 17:56:43
|
I'm not sure..but this is what you may need...declare @t table (col1 int, col2 int, col3 int, col4 int)insert @tselect 1, null, null,1union all select 2, null, null,2union all select null, 10, null,1union all select null, 20, null,2union all select null, null, 30,1union all select null, null,40,2select col4,max(col1),max(col2),max(col3) from @tgroup by col4 |
 |
|
|
subt13
Starting Member
11 Posts |
Posted - 2010-01-07 : 18:05:01
|
[quote]Originally posted by vijayisonly I'm not sure..but this is what you may need...declare @t table (col1 int, col2 int, col3 int, col4 int)insert @tselect 1, null, null,1union all select 2, null, null,2union all select null, 10, null,1union all select null, 20, null,2union all select null, null, 30,1union all select null, null,40,2select col4,max(col1),max(col2),max(col3) from @tgroup by col4 Perfect! Hard to believe it was that simple.Thanks so much. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-07 : 23:19:50
|
| Np. You're welcome. |
 |
|
|
|