I have a table and a trigger
create table test(id int not null identity(1,1) primary key, data int);
create trigger insteadTestInsert ON test INSTEAD OF INSERT
AS
BEGIN
INSERT INTO test(data) select data FROM inserted;
END;
When trigger is enabled, the following query
declare @tmp_table table(id int, int_val int);
insert into test(data)
output inserted.* into @tmp_table
values (10);
select * from @tmp_table;
returns id = 0, int_val = 10 .
If I disable(or drop) the trigger, the query returns the proper value of id.
How to make OUTPUT insert proper results into table variable?
This one actually works.
The restriction is that you must NOT have any other triggers on the table
testthat would “corrupt” the @@identity variable.