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.
| Author |
Topic |
|
sadderson
Starting Member
13 Posts |
Posted - 2009-08-29 : 18:48:31
|
| need to sum different rows for exampleTicket ID1 ID2 value1 1 null 30 1 2 null 201 3 1 101 4 2 52 1 null 52 2 null 102 3 1 202 4 2 30Result needs to be (ID2 doesn't matter)1 1 401 2 252 1 252 2 35all ID1 + ID2 summed to the value (can be a different name or not) ThanksScott |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-08-29 : 19:48:37
|
| SELECT Ticket, COALESCE(ID2, ID1) ID, Sum(Value) FROM myTableGROUP BY Ticket, COALESCE(ID2, ID1)The result you posted for 2,2 is not consistent with the source data you posted and the results for the other values. |
 |
|
|
sadderson
Starting Member
13 Posts |
Posted - 2009-08-29 : 20:05:40
|
| Sorry right 2 2 result should be 40 my mistake.. |
 |
|
|
sadderson
Starting Member
13 Posts |
Posted - 2009-08-29 : 20:24:35
|
| Thanks ... works like a charm...Scott |
 |
|
|
|
|
|