Statement contains an OUTPUT clause without INTO clause error using trigger in SQL Server 2012? -


i have trigger auditing record insert,update , delete. code is

set ansi_nulls on go set quoted_identifier on go  alter trigger [dbo].[mytable_insertafter_audit] on [dbo].[mytable] after insert, delete, update  begin     set nocount on;      declare @action char(1);     set @action = (case when exists(select * inserted)                          , exists(select * deleted)                             'u'  -- set action updated.                         when exists(select * inserted)                             'i'  -- set action insert.                         when exists(select * deleted)                             'd'  -- set action deleted.                         else null -- skip. may have been "failed delete".                        end)      if (@action = 'i')     begin         insert audit_trg             select                  lr.sanction_status, i.sanction_status,                 getdate(), lr.id, 'mytable', @action                              mytable lr             inner join                 inserted on i.id = lr.id     end     else if (@action = 'u')     begin         insert audit_trg             select                 i.sanction_status, lr.sanction_status,                 getdate(), lr.id, 'mytable', @action                              mytable lr             inner join                  deleted on i.id = lr.id     end     else     begin         insert audit_trg             select                 lr.sanction_status, i.sanction_status,                 getdate(), lr.id, 'mytable', @action                               mytable lr             inner join                 deleted on i.id = lr.id     end end 

and audit_trg table

create table [dbo].[audit_trg] (     [id] [int] identity(1,1) not null,     [old_status] [varchar](50) null,     [new_status] [varchar](50) null,     [u_datetime] [datetime] null,     [ref_id] [int] null,     [table_name] [varchar](50) null,     [actions] [varchar](50) null,      constraint [pk_audit_trg]          primary key clustered ([id] asc) ) on [primary] 

but error after inserted is

the target table 'dbo.mytable' of dml statement cannot have enabled triggers if statement contains output clause without clause.


Comments

Popular posts from this blog

Ansible warning on jinja2 braces on when -

Parsing a protocol message from Go by Java -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -