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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem performing update sql

Status
Not open for further replies.

mjlong999

Programmer
Feb 12, 2002
9
US
Using SQL Server 7 (very soon 2000)!

I have two tables (a & b) that have the same key (a.key, b.key) and a few of the same fields (a.checksum, b.checksum). I'm trying to compare the records in these tables, and wherever the same keys do not have matching checksum fields, then I would like to update the B table rows, with the corresponding A table row data.

Below is the sql I am using which works if only 1 record is different between the two tables, but crashes when there are multiple records found.

update b
set b.checksum = (select a.checksum from a,b
where a.checksum != b.checksum
and a.key = b.key)
where b.key in
(select b.key from a, b
where a.checksum != b.checksum
and a.key = b.key);

Any suggestions or help is much appreciated!!!
Thanks,
Mike Long
 
Try this...

Update tableB
Set Checksum=a.Checksum
From tableB b
Join tableA a
On a.key=b.key
Where b.checksum!=a.checksum
Terry L. Broadbent - Salt Lake City, UT
Home of the 2002 Winter Olympics (Feb 8-24)
 
It worked!!!! Thank you so much Terry!!!!!!!!!!!!!!!!!!!!!

--Mike Long
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top