UPSERT in SSIS

前端 未结 8 1125
生来不讨喜
生来不讨喜 2021-01-03 00:37

I am writing an SSIS package to run on SQL Server 2008. How do you do an UPSERT in SSIS?

IF KEY NOT EXISTS
  INSERT
ELSE
  IF DATA CHANGED
    UPDATE
  ENDIF
ENDI         


        
8条回答
  •  迷失自我
    2021-01-03 01:31

    Apart from T-SQL based solutions (and this is not even tagged as sql/tsql), you can use an SSIS Data Flow Task with a Merge Join as described here (and elsewhere).

    The crucial part is the Full Outer Join in the Merger Join (if you only want to insert/update and not delete a Left Outer Join works as well) of your sorted sources.

    followed by a Conditional Split to know what to do next: Insert into the destination (which is also my source here), update it (via SQL Command), or delete from it (again via SQL Command).

    1. INSERT: If the gid is found only on the source (left)
    2. UPDATE If the gid exists on both the source and destination
    3. DELETE: If the gid is not found in the source but exists in the destination (right)

提交回复
热议问题