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
418 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

895 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