Solved

SSIS 2008 Lookup Task for Child Table Population

Posted on 2011-03-22
2
583 Views
Last Modified: 2012-05-11
I am creating an SSIS 2008 (R2) package to do a data transformation job.  I have child tables and a parent. The primary key of the child record is stored in a column in the parent.  I want to use SSIS (perhaps the lookup task will do this) to insert records into the child where they do not exist already, and put the appropriate key into the parent table.  Will the Lookup component do this?  

To illustrate, here is the current T-SQL from a stored proc that populates the child table.

How would I accomplish this using SSIS data flow tasks?  Obviously, I can output to a table and execute this SQL but I am wondering if the Lookup, Merge or other tasks would do this more efficiently?


-- This inserts only new records that do not exist
INSERT INTO dbo.Users_ChildTable (    
    FullName
   ,LastName
   ,FirstName
   ,MI
   ,Address1
   ,Address2
   ,PostalCode
   ,Department
   ,SSN
   ,CreateDate
)
SELECT DISTINCT
    a.UserFullName,
    a.UserLastName,
    a.UserFirstName,
    a.UserMI,
    a.UserAddress1,
    a.UserAddress2,
    a.UserPostalCode,
    a.UserDept,
    a.UserSSN,
    GETDATE()
FROM
    dbo.ParentTableData a LEFT JOIN
    dbo.Users_ChildTable u ON
        ISNULL(a.UserLastName,'') = ISNULL(u.LastName,'') AND
        ISNULL(a.UserFirstName,'') = ISNULL(u.FirstName,'') AND
        ISNULL(a.UserMI,'') = ISNULL(u.MI,'') AND
        ISNULL(a.UserAddress1,'') = ISNULL(u.Address1,'') AND
        ISNULL(a.UserAddress2,'') = ISNULL(u.Address2,'') AND
        ISNULL(a.UserPostalCode,'') = ISNULL(u.PostalCode,'') AND
        ISNULL(a.UserDept,'') = ISNULL(u.Department,'') AND
        ISNULL(a.UserSSN,'') = ISNULL(u.SSN,'') 
WHERE
    u.SSN IS NULL AND
    u.LastName IS NULL;
    
-- Now update the key field in the parent for the appropriate UserID

    UPDATE dbo.ParentTableData
    SET dbo.ParentTableData.UserID = u.UserID
    FROM
        dbo.ParentTableData a INNER JOIN
        dbo.Users_ChildTable u ON
        ISNULL(a.UserLastName,'') = ISNULL(u.LastName,'') AND
        ISNULL(a.UserFirstName,'') = ISNULL(u.FirstName,'') AND
        ISNULL(a.UserMI,'') = ISNULL(u.MI,'') AND
        ISNULL(a.UserAddress1,'') = ISNULL(u.Address1,'') AND
        ISNULL(a.UserAddress2,'') = ISNULL(u.Address2,'') AND
        ISNULL(a.UserPostalCode,'') = ISNULL(u.PostalCode,'') AND
        ISNULL(a.UserDept,'') = ISNULL(u.Department,'') AND
        ISNULL(a.UserSSN,'') = ISNULL(u.SSN,'')

Open in new window

0
Comment
Question by:richxyz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
vdr1620 earned 250 total points
ID: 35199489
You can use Lookup to do this.. you will need to do the Lookup on the key column and use OLEDB command Task to update the Values or OLEDB destination to insert values.

In the OLEDB command make sure the parameters are mapped correctly in the same order

http://www.sqlis.com/post/OLE-DB-Command-Transformation.aspx
0
 

Author Closing Comment

by:richxyz
ID: 35235254
I was curious about how efficient, i.e. performance, doing it with the lookup task would be as opposed to my current stored procedure method.  That's why I said PARTIALLY.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question