dbTalk Databases Forums  

Compare two tables in different databases

comp.databases.ms-access comp.databases.ms-access


Discuss Compare two tables in different databases in the comp.databases.ms-access forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ecohouse
 
Posts: n/a

Default Compare two tables in different databases - 01-03-2008 , 02:27 PM






I'm using Access 2003 and will have to separate databases with the
exact same tables and table structures.

I need to be able to compare the table from the second database
against the same table in the first database. I need to know if there
is a similar name in the table in the first db and then find out if
all the rest of the fields are the same. If they aren't I need to
update the table in db1 with the values from db2. If there isn't a
record with a similar name then I need to create a new record in db1.

I was just wondering what the best approach to do this would be? Any
help would be appreciated.

Reply With Quote
  #2  
Old   
Rich P
 
Posts: n/a

Default Re: Compare two tables in different databases - 01-03-2008 , 03:02 PM






Greetings,

For Updating:

UPDATE tbl2 INNER JOIN tbl1 ON tbl2.ID = tbl1.ID and tbl2.Name =
tbl1.Name SET tbl2.fld1 = tbl1.fld1, tbl2.fld2 = tbl1.fld2,
tbl2.fld3=tbl1.fld3

And for missing rows do this:

Insert Into tbl1 t1
Select * From tbl2 t2 Where Not Exists (select * From tbl2 t3 where
t3.ID = t1.ID and t3.Name = t1.Name)



Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.