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)
 scheduled job - transfer unique data between dbs

Author  Topic 

kreplech
Starting Member

10 Posts

Posted - 2007-12-10 : 21:49:46
hello all,

I have the unfortunate need to have a scheduled job that only transfers unique (that is, rows that haven't already been transfered) between two databases. So, if I were transferring cars, and Toyota already exists in database B, how to transfer all rows other than Toyota? I realize I could write a little VB script to do this - I'm just looking for an all SQL solution if possible.

Thanks,
M

singularity
Posting Yak Master

153 Posts

Posted - 2007-12-10 : 22:20:47
insert into db2.dbo.tbl
select * from db1.dbo.tbl
where db1.dbo.tbl.car not in (select car from db2.dbo.tbl)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-10 : 23:56:47
is both database residing on the same SQL Server ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kreplech
Starting Member

10 Posts

Posted - 2007-12-11 : 11:31:28
singularity - yes, i know... i'm looking for more efficient ways to do this since it will be a scheduled job with a lot of data to compare.

khtan - yes, both dbs are on the same server.

i'm not terribly familiar with packages - does this task seem fit to run as a package?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-11 : 11:47:57
use LEFT JOIN instead of NOT IN


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -