Perform Upsert ( Update/Insert SCD1 ) by using Lookup Transformation - SQL Server Integration Services(SSIS) Tutorial

Scenario:

Let's say we have to load a dimension table from text file. Our business Key is SSN. We need to insert new records depending upon values of SSN column, If any new then we need to insert this records. If SSN already existing in Table then we need to find out if any other column is changed from Source columns values. If that is true then we have to update those values.

What we will learn in this video

  1. How to Read the data from Flat file in SSIS Package
  2. How to perform Lookup to Find out Existing or Non Existing Records in Destination Table From Source
  3. How to Insert new Records by using OLE DB Destination
  4. How to update existing Records by using OLE DB Command Transformation in SSIS Package



Solution:

Le't create a table that need Update/Insert operation

CREATE TABLE dbo.DimCustomer
  (
     CustomerID INT IDENTITY(1, 1),
     SSN        VARCHAR(11),
     FirstName  VARCHAR(50),
     LastName   VARCHAR(50),
     Address    VARCHAR(100),
     LoadDate   DATETIME,
     UpdateDate DATETIME,
     LoadedBy   VARCHAR(50),
     ModifiedBy VARCHAR(50)
  )


Sample Data we will use in Source File
SSN,FirstName,LastName,Address
000-000-001,Aamir,Shahzad,NJ USA
000-000-002,John,River,NC USA


Query used in the OLE DB Command Transformation

Update dbo.DimCustomer
SET FirstName=?,
LastName=?,
Address=?,
UpdateDate=?,
ModifiedBy=?
WHERE SSN=?



How to load Slowly Changing Dimension Type 1 by using Lookup Transformation in SSIS Package - SSIS Tutorial



  Related Posts / Videos on Lookup Transformation 

2 comments:

  1. I think you will not need a lookup transformation if you use SSIS Upsert.Although this is a third-party product but I still think it will be useful.

    ReplyDelete
    Replies
    1. Zappysys 3rd party tool is $999/yr to own just their standard edition.

      Delete