SolvedPrivate

merge more than two tables in ssis

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

My client sends a request to me that they want me to load data, which will be returned by Web Service APIs, and do some transformation before importing to database. In this article, I will provide an approach to load data with Web Service Task and X…
Here's a requirements document template for an integration project (also known as Extract-Transform-Load or ETL) based on my development experience as an SQL Server Information Services (SSIS) developer over the years.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

911 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

22 Experts available now in Live!

Get 1:1 Help Now