Solved

SSIS 2008 Lookup Task for Child Table Population

Posted on 2011-03-22
2
586 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

696 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