SolvedPrivate

merge more than two tables in ssis

Posted on 2014-10-29
3
18 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

685 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