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
421 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
[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
  • 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

739 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