Home

Published

- 1 min read

tsql goup by clause in merge statement

img of tsql goup by clause in merge statement

The solution for this is noted below

tsql goup by clause in merge statement

Solution

   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
;

Try other methods by searching on the site. That is if this doesn’t work