Wednesday, March 01, 2017

T-SQL: Merge

MERGE as target
USING (
SELECT ***
FROM tbl g
WHERE @***

) AS source (A_ID, B_ID)
ON ( target.A_IdMembro = @Id )
WHEN MATCHED THEN
UPDATE SET ID = source.ID
WHEN NOT MATCHED THEN
INSERT (colunas)
VALUES ( @Id
, source.ID
, ...
)
;