SQL Bulk Update MERGE ... UPDATE ... - MRLIVING/Becca GitHub Wiki

The SQL Merge Update can help us bulk update the target table (columns) from the source table (columns) according to the match conditions.
As illustrated below, we want to fill the U_m2_itemID from the source item_id under matched DocEnty and LineNum.

image

MERGE ${Tagrget_Table}
USING (
  ${Source Table, SELECT ... FROM ...}
) 
ON 
  ${Record Condition to Update}
WHEN MATCHED THEN 
UPDATE SET 
  ${Tagrget_Table}.${Col1} = ${Source Table}.${ColA}
  ${Tagrget_Table}.${Col2} = ${Source Table}.${ColB}
  ...
;

Reference