1MERGE esqlProductTarget T
2USING esqlProductSource S
3ON (S.ProductID = T.ProductID)
4WHEN MATCHED
5 THEN UPDATE
6 SET T.Name = S.Name,
7 T.ProductNumber = S.ProductNumber,
8 T.Color = S.Color
9WHEN NOT MATCHED BY TARGET
10THEN INSERT (ProductID, Name, ProductNumber, Color)
11 VALUES (S.ProductID, S.Name, S.ProductNumber, S.Color)
12WHEN NOT MATCHED BY SOURCE
13THEN DELETE;
1MERGE dbo.MyTarget targ
2USING (SELECT ... FROM dbo.MySource GROUP BY .....) src
3ON (targ.Identifier = src.Identifier
4 AND targ.Name = src.ConstituentName
5 AND targ.Ticker = src.ConstituentTicker
6 AND (targ.CUSIP = src.CUSIP OR targ.ISIN = src.ISIN OR targ.SEDOL = src.SEDOL))
7WHEN MATCHED THEN
8-- update values
9;
1MERGE LoginTypes T
2 USING (SELECT 'System' as Description) S
3 ON(S.Description = T.Description)
4WHEN NOT MATCHED BY TARGET
5 THEN INSERT(Description, CreatedTimestamp, LastUpdatedTimestamp)
6VALUES('System', getdate(), getdate());