SQL Server 2005+
I have a view with an INSTEAD OF INSERT
trigger. Inside the body of the trigger, I want to use a statement with an OUTPUT
clause which references both INSERTED
tables:
- the outer
INSERTED
table for theINSTEAD OF INSERT
trigger - the inner
INSERTED
table for theOUTPUT
clause
MSDN says this:
If a statement that includes an OUTPUT clause is used inside the body of a trigger, table aliases must be used to reference the trigger inserted and deleted tables to avoid duplicating column references with the INSERTED and DELETED tables associated with OUTPUT.
But aliasing doesn't seem to work:
CREATE TRIGGER v_insert ON v
INSTEAD OF INSERT
AS BEGIN
INSERT INTO t (a, b, c)
OUTPUT inserted.a, inserted.b, outer_inserted.d INTO t_prime (a, b, d)
SELECT a, b, c
FROM inserted as outer_inserted
END
It produces the error "The multi-part identifier "outer_inserted.d" could not be bound. Does that mean what I'm trying to do is not possible?