Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Comparing the values in 2 tables
Message
 
 
To
02/04/2009 11:32:16
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01392746
Message ID:
01392784
Views:
42
This message has been marked as a message which has helped to the initial question of the thread.
Daniel,

Use the Binary_CheckSum function. It can aggregate a value for all the columns you are comparing, it works pretty fast too. I had to put together a process that compared multimillion row tables to find the rows that needed updating.
select Main.PK
   from Main
   inner join Secondary
      on Main.PK = Secondary.PK
   where binary_checksum( Main.ColA, Main.ColB, Main.ColC ... ) !=
         binary_checksum( Secondary.ColA, Secondary.ColB, Secondary.ColC ... )
You can use left joins or exists checks to find the rows that need to be inserted.

>I already have this done in Foxpro, scaning and comparing data in 2 tables, but is there a way
>to do this in SQL Server using SQL???
>Basically I have 2 tables that are identical in structure, but the data in one table may not be the same as the other, so I want to find out where the discrepancies are. Is this possible?
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform