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 2005 Forums
 Transact-SQL (2005)
 Comparing Tables in SQL 2k5

Author  Topic 

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-16 : 22:47:26
Hi All,

I am working with an imported table that takes data from a text file in the server. this text file is updated daily at 07AM.(i.e new record are added or old ones are deleted).
I need to compare today's table with the existing one and throw any changes(new record or old record deleted) in a separate table with a time stamp ?
All tables have idex field which is te Employee ID.
PLease any help will be appreciated.


thanks for the help

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2009-03-17 : 03:50:33
You can compute the checksum for the rows in existing and newly imported rows, using the CHECKSUM() function and then compare checksum values of both tables based on EmployeeID. Non-equal checksum values indicate changes to the row which you can throw to different table.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

korssane
Posting Yak Master

104 Posts

Posted - 2009-03-17 : 09:53:25
thanks budd. for the idea . i wil try this and let you know.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-17 : 09:56:59
this should be good read as well.

http://weblogs.sqlteam.com/jeffs/archive/2004/11/10/2737.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-17 : 11:01:38
you can also use ssis package for this purpose which gets the data from file using flat file source and then uses below method before insert/update/deleting the records from destination table.

http://www.sqlis.com/post/Get-all-from-Table-A-that-isnt-in-Table-B.aspx
Go to Top of Page
   

- Advertisement -