SolvedPrivate

merge more than two tables in ssis

Posted on 2014-10-29
3
19 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:Auerelio Vasquez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Auerelio Vasquez
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

737 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