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 2000 Forums
 SQL Server Development (2000)
 Insert Records From Second Table

Author  Topic 

oahu9872
Posting Yak Master

112 Posts

Posted - 2005-10-12 : 12:55:47
I have two tables of data. One table is used for backup and is cleared and uploaded weekly, then used to compare against the primary table. What I would like to do is run a stored procedure that has the backup table insert records into the primary table if they are not already there.

The field I would check is Account so I would tell it to insert into the table where Account does not exist.

I think this would use the "Not In" or "Exists" functions.


Thanks

SreenivasBora
Posting Yak Master

164 Posts

Posted - 2005-10-12 : 15:55:50
If you filter data only on "Account" column then use "NOT in"
Multiple columns join then use Exists.

See books online for more help.

With Regards
BSR
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-10-12 : 17:38:44
How about a LEFT JOIN instead?

INSERT INTO primarytable
SELECT ...
FROM backuptable b
LEFT JOIN primarytable p on b.AccountKey = p.AccountKey
WHERE p.AccountKey IS NULL

---------------------------
EmeraldCityDomains.com
Go to Top of Page
   

- Advertisement -