Solved

SSIS 2008 Lookup Task for Child Table Population

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

829 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