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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Data table comparisons?

Author  Topic 

dlorenc
Posting Yak Master

172 Posts

Posted - 2011-05-24 : 16:48:06
I have one table which contains asset tracking information (historical). I want to pull asset information from the Microsoft SMS tool and dump it into a second table...

now I want to produce a discrepency report that shows what fields in the first asset tracking data table needs to be reviewed/updated based on the current SMS report(s)...

how do I compare two tables and show the differences?

both tables have an asset tag ID as they key field...and the first table has many more data fields in it than the second...but the second tables fields exist in the first table..and the first table has many more assets in it than are reported on by the SMS product...and there are never any assets deleted from the first, but SMS may find some new assets not yet entered in the first...

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-24 : 16:58:33
select <columns to compare > from secondTable
EXCEPT
select <those same columns to compare> from firstTable

will give you all the records from the secondTable that are somehow different
from the firstTable

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-24 : 16:58:34
select <columns to compare > from secondTable
EXCEPT
select <those same columns to compare> from firstTable

will give you all the records from the secondTable that are somehow different
from the firstTable

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -