Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update using the sum of 2 records

Status
Not open for further replies.

pflakes

Technical User
Jan 27, 2004
31
US
The basic idea behind what I'm trying to do is --

update bits of 'reporta' by setting it to the sum of bits of 'reporta' and 'reportb' where the timestamps of reporta and reportb match. The bits of reportb should remain untouched.

Here's what I'm trying - I understand why it's not working but can't figure out how to resolve my problem.

update table1
set bits =
(select sum(bits)
from table1
where
report_id in (select report_id from table1
where report_id in ('reporta','reportb'))
and timestamp = timestamp)
and report_id = 'reporta'


Any help that can point me in the right direction would be greatly apprecited.
 
Maybe something like this will work?

Code:
Update Table1 A
   Set Bits = Bits + 
       (Select Sum(Bits)
          From Table1 B
         Where Report_Id = 'Reportb'
           And B.Timestamp = A.Timestamp)
 Where Report_Id = 'Reporta'


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you! After a little work to eliminate some nulls, it's working just as I'd hoped.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top