SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 IF EXISTS Check for Bulk Insert
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sameer.softyhcl
Starting Member

India
2 Posts

Posted - 10/16/2012 :  04:45:54  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 10/16/2012 :  05:32:48  Show Profile  Visit webfred's Homepage  Reply with Quote
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

India
2 Posts

Posted - 10/17/2012 :  02:42:20  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000