SolvedPrivate

merge more than two tables in ssis

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now