Refine the ON clause to ensure a target row matches at most one source row, or use the GROUP BY clause to group the source rows code example

Example: 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
-- update values
;

Tags:

Sql Example