Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SSIS 2008 Lookup Task for Child Table Population

Posted on 2011-03-22
2
Medium Priority
?
597 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 750 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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

971 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