Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append Results of SQL Query to Table

Status
Not open for further replies.

supermatchgame

Programmer
May 16, 2007
50
GB
Every night I import 4 tables from an Oracle database into a SQL Server database. I drop a that holds the results of a query run against these 4 tables, and then run a 'SELECT INTO' query to re-build the table afresh every night.

What I would like to do now is not rebuild this table every night, but just append it with a) any changes to the results that come out of my query and b) any new rows that come out of my query. I then want to set triggers on the table to make certain things happen on an update or insert. But I'm not sure how to make this work.

I assume that the best way to make this happen every night is to write a DTS package, but I'm not sure how to append the table.

Can anyone help?
 
insert into t1 select * from t2 where t2.id not in (select id from t1)

something like that?

--------------------
Procrastinate Now!
 
Code:
insert table1 (field1, field2)
select field1, field2 from table2 t2
left join table1 t1 on t1.field1 = t2.field1
where t1.field1 is null

when you write the trigger, make sure it handles multiple record insert and updates. Test to be sure!

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top