I need to know if the MERGE INSERT statement was executing. In my script, the insert is either 0 or 1 line.
Test code:
DECLARE @t table (C1 int, C2 int)
DECLARE @C1 INT, @C2 INT
set @c1 = 1
set @c2 = 1
MERGE @t as tgt
USING (SELECT @C1, @C2) AS src (C1, C2)
ON (tgt.C1 = src.C1)
WHEN MATCHED AND tgt.C2 != src.C2 THEN
UPDATE SET tgt.C2 = src.C2
WHEN NOT MATCHED BY TARGET THEN
INSERT VALUES (src.C1, src. C2)
OUTPUT deleted.*, $action, inserted.*;
SELECT inserted.*
The last line does not compile (unlike a trigger, there is no scope). I cannot access @action or output. In fact, I do not want any output metadata.
How can i do this?
source
share