I have 2 different Servers (Server1 and Server2). On each is a database (db1 and db2) with a similar structure. There are continuous data inserts in db1.
I want a job extracting the data from one server (db1) to the other server (db2) on a daily schedule using SSIS and SQL Server agent for the scheduler. I only want transfer the new Data (the data which is not transferred in an earlier job) to the db2.
For this I want to select the last Id from db2 and use it to transfer only the data from db1 which have a higher id.
The concept itself works, but I don't know how to implement it with SSIS.
In SSIS I tried to use SQL execution tasks and safe it into variables:
First task (to safe the id in a variable):
SELECT TOP (1) [ID] FROM [DB2] ORDER BY ID DESC
Second task (safe the rows into object variable):
SELECT * FROM [DB1] where ID > ?
That works, but how can I insert the object variable into the db2.
Isn't there a cleaner way like:
Insert into Server2.[db2] select * from Server1.[db1] where ID > ?
The problem is, that SSIS only allows one connection for each SQL execution (same problem with dataflow tasks).
I also thought about temporary tables. But I'm not sure if this is the right way.
Would be awesome if someone got an idea / hint. I have not found much about this and I guess its an simple task.
Thanks a lot.
You are most of the way there. Just use a dataflow task instead of an execute SQL task. A data flow can have two different connections.