Reputation: 131
I have 2 columns that makes a record unique, so I want to merge with multiple keys. How can I do this?
I tried this but it doesnt seem to work:
MERGE INTO TABLE1 AS DST
USING TABLE2 AS SRC
ON SRC.pk1 = DST.pk1
AND
SRC.pk2 = DST.pk2
WHEN NOT MATCHED THEN
INSERT (pk1, pk2, Description)
VALUES (SRC.p1, SRC.pk2, SRC.Description)
;
Upvotes: 1
Views: 4159
Reputation: 138990
What you have here will insert rows from table2
to table1
. Except for a typo in the values clause you have it. Change SRC.p1
to SRC.pk1
.
Try here: https://data.stackexchange.com/stackoverflow/q/120421/
Upvotes: 4