Solved

4. SSIS- Using one SQL command, how can you insert and update data into a table? Are there any drawbacks using this method?

Posted on 2014-10-15
5
420 Views
Last Modified: 2016-02-11
I'm wondering, when I use a single SQL command in SSIS, how do I do an "insert and update to data in a table"?

Are there any drawbacks using this method?
0
Comment
Question by:MIKE
  • 2
  • 2
5 Comments
 
LVL 3

Assisted Solution

by:prequel_server
prequel_server earned 167 total points
ID: 40383576
insert is simple and fast,
for updates you'll have to check if the id exists and then you update all columns or changed ones if you like.

if your dataset contains both new and updates you split the rows and process them two sets in separate branches of your data flow.
0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 166 total points
ID: 40384137
What is the source of your data (e.g. file, another table, etc.)?
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 167 total points
ID: 40384238
Eyeballeth thy MERGE statement, introduced in SQL 2008, which can perform both an insert and update in a single statement.

I use this all the time for loading data warehouses.

SSIS out of the box does not have a MERGE control, so you'd have to lookup on all key columns, to determine if the row does not currently exist (INSERT), then lookup on all columns to determine if it's an UPDATE or no change. Takes a long time to code and test.  If you have some money to burn buy Pragmatic Works Task Factory which has an UPSERT control which does this in one component.
0
 
LVL 32

Expert Comment

by:awking00
ID: 40384697
The merge statement is the best way to go if the source data is a table, which is why I asked.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40386818
So ... is this question answered?
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

820 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