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
417 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 31

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 31

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

747 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

14 Experts available now in Live!

Get 1:1 Help Now