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
 SSIS and Import/Export (2005)
 IF EXISTS Check for Bulk Insert

Author  Topic 

sameer.softyhcl
Starting Member

2 Posts

Posted - 2012-10-16 : 04:45:54
Team,

I needed to purge database records to Archive Database. I have some 70 Tables.
I am doing INSERT INTO <Database1>.<TABLE1>.. SELECT * FROM <Database2>.<TABLE1>...

Now it is required to check IF EXISTS for records. If the record exist in Archive Database for a table, no need to insert again.

Please suggest some efficient ways.

edit: moved to proper forum

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-10-16 : 05:32:48
insert DestinationTable
select * from SourceTable as t
where not exists(select * from DestinationTable where DestinationTable.KeyColumn = t.KeyColumn)


Too old to Rock'n'Roll too young to die.
Go to Top of Page

sameer.softyhcl
Starting Member

2 Posts

Posted - 2012-10-17 : 02:42:20
thanks a ton, it worked
quote:
Originally posted by webfred

insert DestinationTable
select * from SourceTable as t
where not exists(select * from DestinationTable where DestinationTable.KeyColumn = t.KeyColumn)


Too old to Rock'n'Roll too young to die.

Go to Top of Page
   

- Advertisement -