SolvedPrivate

merge more than two tables in ssis

Posted on 2014-10-29
3
17 Views
Last Modified: 2016-02-11
I have a few queries, that i would like to merge into one table based on a pk and a date key.

I hvae the queries, but in SSIS it looks like you can't merge more than two tables. What is the best way to do this in a transact -sql statement ?
0
Comment
Question by:basile
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40410649
>I have a few queries, that i would like to merge into one table based on a pk and a date key.
Can you write 'these queries' as a single SQL Stored Procedure, that returns all of this as one set using UNION / UNION ALL / MERGE / JOINs / whatever, and then refer to that SP as an SSIS data source?

>but in SSIS it looks like you can't merge more than two tables.
True, but you can use multiple MERGE components to pull off merging more than two tables.
Kinda hokey I know.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40410670
You can use the Execute SQL function.
0
 
LVL 1

Author Comment

by:basile
ID: 40413750
ok, so i tried this merge statement, it works on the first pass, but when there is data, i get a message that says:

Msg 8672, Level 16, State 1, Line 1
The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than one source row. A MERGE statement cannot UPDATE/DELETE the same row of the target table multiple times. Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows.

any ideas ?


with busies as

(select imp_CallType.dt_DateTime, imp_CallType.str_EnterpriseName, imp_CallType.int_CallsOffered from
dbo.imp_CallType
inner join tbl_MasterMeasureMapping on
imp_CallType.str_EnterpriseName = tbl_MasterMeasureMapping.str_EnterpriseName
where tbl_MasterMeasureMapping.str_Busies = 'True' and
tbl_MasterMeasureMapping.str_DataType='Call Type' and
tbl_MasterMeasureMapping.str_Network = 'ATT')

 MERGE  stg_Fact_CallType AS target_table
        USING busies AS source_table
        ON            source_table.str_EnterpriseName = target_table.str_EnterpriseName
                and source_table.dt_DateTime = target_Table.dt_DateTime
        WHEN      MATCHED
            THEN      UPDATE
               SET         target_table.int_CallsOffered = source_Table.int_CallsOffered
        WHEN      NOT MATCHED BY TARGET
            THEN      INSERT
            (dt_DateTime,str_EnterpriseName,int_CallsOffered)
               VALUES       (dt_DateTime,
                                           str_EnterpriseName,
                             int_CallsOffered
                             
                            ) ;
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

786 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