R2D2
R2D2

Reputation: 131

Merge with multiple primary keys

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

Answers (1)

Mikael Eriksson
Mikael Eriksson

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

Related Questions