sql merge syntax example
Example 1: sql merge
-- Oracle: Example for Insert or update in t1 from t2 values
MERGE INTO table1 t1
USING table2 t2
ON (t1.CODE = t2.ID)
WHEN MATCHED THEN
UPDATE SET t1.COL1 = t2.VALUE1
WHEN NOT MATCHED THEN
INSERT (CODE, COL1) VALUES (t2.ID, t2.VALUE1);
Example 2: sql merge statement
MERGE LoginTypes T
USING (SELECT 'System' as Description) S
ON(S.Description = T.Description)
WHEN NOT MATCHED BY TARGET
THEN INSERT(Description, CreatedTimestamp, LastUpdatedTimestamp)
VALUES('System', getdate(), getdate());