merge target source sql code example
Example 1: tsql goup by clause in merge statement
MERGE dbo.MyTarget targ
USING (SELECT ... FROM dbo.MySource GROUP BY .....) src
ON (targ.Identifier = src.Identifier
AND targ.Name = src.ConstituentName
AND targ.Ticker = src.ConstituentTicker
AND (targ.CUSIP = src.CUSIP OR targ.ISIN = src.ISIN OR targ.SEDOL = src.SEDOL))
WHEN MATCHED THEN
;
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());