MERGE [AS TARGET] 
  USING [AS SOURCE]

  ON (TARGET.CodeID = SOURCE.CodeID)
   
    --When records are matched, update
    --the records if there is any change
  [WHEN MATCHED THEN ]
    UPDATE SET TARGET.TaxCode = SOURCE.TaxCode;
 
   --When no records are matched, insert
   --the incoming records from source
   --table to target table
  [WHEN NOT MATCHED [BY TARGET] THEN ]
   INSERT ......
 
    --When there is a row that exists in target table and
   --same record does not exist in source table
   --then delete this record from target table
  [WHEN NOT MATCHED BY SOURCE THEN ];
    DELETE
 

OUTPUT $action,

   DELETED.CodeID AS TargetCodeID,
   DELETED.TaxCode AS TargetTaxCode,
   DELETED.AppendCode AS TargetAppendCode,
   DELETED.CodeName AS TargetCodeName,
   INSERTED.CodeID AS SourceCodeID,
   INSERTED.TaxCode AS SourceTaxCode,
   INSERTED.AppendCode AS SourceAppendCode,
   INSERTED.CodeName AS SourceCodeName;

(要以分号结束)
select @@ROWCOUNT;

相关文章:

  • 2022-01-14
  • 2021-07-28
  • 2022-12-23
  • 2021-10-18
  • 2021-08-23
  • 2021-08-26
  • 2021-09-16
  • 2021-10-06
猜你喜欢
  • 2021-08-13
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
相关资源
相似解决方案