We often need in the incremental load of various tables (from source to destination) that old records must be updated and new records inserted.

Step 1: Finding the columns of the source tables from which we can determine that a particular records is a new record or it is the old one.

For e.g. I am taking a Student (Source) table. It's structure is:

SSIS1.gif

By looking at it's table structure we easily find that we can determine whether a record is old/new by the createdate and modidate.

New record -> Createdate = Modidate
Old Record -> Createdate <> Modidate

Step 2: Create an SSIS Package
Step 3: Add Oledb connection for source and destination Step 4: Add a dataflow task into package

SSIS5.gif

Step 5: Rename it to Student_incr

Step 6: Add three variable of the package level scope

Date_From : Int32,
Date_To: Int32
Query_Student: String

SSIS6.gif

Set the value of package variable as shown above.

Here Query_Student variable will contain the SQL incremental query:
  1. SELECT * from Student
  2. WHERE (CAST(CONVERT(VARCHAR(10), Createdate, 111) AS DATETIME) >= CAST(CONVERT(VARCHAR(10), DATEADD(Day, " +(DT_WSTR,50)@[User::Days_From]+", GETDATE()), 111) AS DATETIME)) AND (CAST(CONVERT(VARCHAR(10), Createdate, 111) AS DATETIME) < CAST(CONVERT(VARCHAR(10),DATEADD(Day, "+(DT_WSTR,50)@[User::Days_To]+", GETDATE()), 111) AS DATETIME))
Paste this query in the expression property of the Query_Student variable

SSIS7.gif


Step 7: Double click Student_incr dataflow task You are through.