Skip to content
Amal Hashim
All posts
Article

SSIS - Nightly import package that updates and inserts records

Build an SSIS package that imports from a source view, updating existing records and creating new ones, using Lookup and Conditional Split.

2 min read#SQL#Tools

This walkthrough builds an SSIS package for a nightly import. Records already imported are updated, and new records are created in the destination.

For the demo, assume a source system (say a CRM) with a view like this:

Source view in the CRM database

The job imports this data into an Employee table in the destination:

Destination Employee table

Steps

  1. Open SQL Business Intelligence Studio and create a new "Integration Services Project".

New Integration Services project

  1. From the toolbox, drop a Data Flow Task onto the control flow.

Data Flow Task on the control flow

  1. Double click it and add an OLE DB Source.

OLE DB Source added to the data flow

  1. Double click the OLE DB Source.

OLE DB Source editor

  1. Click New to create a connection and enter the source database details. Select the connection and set the other properties.

Source connection and view selected

  1. Add a Lookup transformation. It tells us whether the record already exists in the destination.

Lookup transformation added

  1. Add a connection to the destination first.

New connection to the destination

  1. Set up the Lookup transformation.

Lookup transformation settings

  1. By default, a Lookup fails when no match is found. That is exactly the case for new records, so set the Error Output to let them through the pipeline.

Lookup error output configuration

  1. Add a Conditional Split.

Conditional Split added

  1. Drag the data flow arrow into the Conditional Split. In the dialog, select "Lookup Match Output".

Input Output Selection dialog

  1. Double click the Conditional Split and define the outputs.

Conditional Split conditions

  1. Add an OLE DB Destination and an OLE DB Command. Connect the New_Records output to the destination, and the Modified_Records output to the command.
  2. Configure the OLE DB Destination.

OLE DB Destination connection

OLE DB Destination column mappings

  1. Configure the OLE DB Command.

OLE DB Command connection

OLE DB Command SqlCommand property

SQL update statement for the OLE DB Command

OLE DB Command parameter to column mappings

  1. Press F5 to run and test the package.

Data flow after running the package

The package is ready. Scheduling it to run every night is the next step.