Here's a good example of a MERGE statement:
MERGE INTO target AS T
USING source AS S
ON T.ID = S.ID and T.tran_time = S.tran_time
WHEN MATCHED UPDATE SET quantity = S.quantity
WHEN MATCHED AND S.quantity IS NULL THEN DELETE
WHEN NOT MATCHED THEN INSERT VALUES (S.ID, S.quantity, S.tran_time);
When doing the INSERT, does it have to exactly match the structure of the target table, or can a column list be somehow be specified like in a simple INSERT statement? I don't like hard coding value lists that have to match the order of the columns in the table, I like my statements to be column order independent.
Asked by PhilHibbs
(539 rep)
Apr 30, 2020, 01:52 PM
Last activity: Apr 30, 2020, 07:06 PM
Last activity: Apr 30, 2020, 07:06 PM