[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

UPSERT in SSIS

I have an ERP system with an ORD_HDR(about a million rows) table and an ORD_DTL(about 7 million rows) table. Initially there was an ODBC connection to the ERP system and it was a query  on the ORD_HDR table with an INNER JOIN to the details table for the last 10 days with a Slowly Changing dimension to insert or update the table and then a bunch of Lookups and then loading a Fact table. This took over an hour and a half to run. So I loaded all the data into SQL tables and then want to use those tables to do the UPSERT. My initial problem is that I have to check the ERP data against my tables that are loaded already and do an Insert or Update if it exists already or not. I wanna do this the fastest way possible so Im open to suggestions. I have to query the ERP tables, match the records against the tables I loaded today and do an Insert if it doesnt exist and an Update if it does. I dont even beleive the Update is necessary but I guess it was necessary on the SCD I guess? Please help!!!
0
jknj72
Asked:
jknj72
  • 3
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>Insert if it doesnt exist and an Update if it does.
Have you tried a MERGE statement, which can perform inserts, updates, and deletes in a single statement?  

Scoll down for examples.  Assumes 2008 and higher.
0
 
jknj72Author Commented:
This may be exactly what Im looking for I just have to figure out how to write the syntax, I have like 200+ fields in my select statement. Can I just check like 3 source fields against 3 dest fields and then do the insert with all the columns? If this works I will buy you dinner!!!!
0
 
jknj72Author Commented:
Jim, do you have any experience with the Merge task in SSIS?
0
 
jknj72Author Commented:
Thanks for pointing me in the right direction. I have another question out there for how to do the Merge, if your interested
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now