You can create a table variable to save the type of action and then OUTPUTthe pseudo column $action.
Example
DECLARE @A TABLE (
[id] [int] NOT NULL PRIMARY KEY CLUSTERED,
[C] [varchar](200) NOT NULL)
INSERT INTO @A
SELECT 1, 'A' UNION ALL SELECT 2, 'B'
DECLARE @Actions TABLE(act CHAR(6))
MERGE @A AS target
USING (VALUES (1, '@a'),( 2, '@b'),(3, 'C'),(4, 'D'),(5, 'E')) AS source (id, C)
ON (target.id = source.id)
WHEN MATCHED THEN
UPDATE SET C = source.C
WHEN NOT MATCHED THEN
INSERT (id, C)
VALUES (source.id, source.C)
OUTPUT $action INTO @Actions;
SELECT act, COUNT(*) AS Cnt
FROM @Actions
GROUP BY act
Returns
act Cnt
------ -----------
INSERT 3
UPDATE 2
source
share