This is the syntax that I use for insert/update:

MERGE Table2 AS TARGET
USING (
    SELECT Column1, Column2, Column3
    FROM Table1
) AS SOURCE ([Table1].Column1, [Table1].Column2, [Table1].Column3)
ON TARGET.Column1 = SOURCE.Column1 AND TARGET.Column2 = SOURCE.Column2
WHEN MATCHED THEN
    UPDATE
    SET [Table2].Column1 = SOURCE.Column1,
        [Table2].Column2 = SOURCE.Column2,
        [Table2].Column3 = SOURCE.Column3
WHEN NOT MATCHED THEN
    INSERT
    (
        [Table2].Column1,
        [Table2].Column2,
        [Table2].Column3
    )
    VALUES
    (
        SOURCE.Column1,
        SOURCE.Column2,
        SOURCE.Column3
    );

Advertisements