Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Microsoft SQL Server
Category:
Database management
Environment versions
SQL Server:
SQL Server 2000
>Given a large database, and a complete new set of data that may have many duplicates with the existing set of data, what would be the most efficient way to find the differences (items no loger there, items new, and items modified)??
Well, I've had good results with using 2 sql commands provided there is a common ID between the two files.
select * from table1 tgt ;
inner join table2 src on tgt.id = src.id ;
where ;
src.field1 # tgt.field1 ;
or src.field2 # tgt.field2 ;
into cursor c_Modifications
Repeat as many fields as you have. I think the first field that is different stops the processing of the remaining OR conditions.
select * from table2 src ;
where src.id not in (select id from table1) ;
into cursor c_Additions
A third query could give the records that are no longer in the new set of data.
select * from table1 src ;
where src.id not in (select id from table2) ;
into cursor c_Removed
HTH
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only