sql server - SQL Trigger getting invoked more than once -


i have insert trigger follows:

alter trigger [dbo].[trackinginitialize]    on  [dbo].[workschedule_]     after insert     declare @work_area varchar(255);     declare @schedule_date date;     declare @employee1 varchar(255);     declare @hours1 float;  begin      set nocount on;      select @work_area=i.workarea inserted i;     select @schedule_date=i.scheduledate inserted i;     select @employee1=i.employee1 inserted i;     select @hours1=i.hours1 inserted i;      select @ccname = costcenter_.name     workarea_, costcenter_     workarea_.costcenterid = costcenter_.id , workarea_.workareaname = @work_area      if (@employee1 not null)     begin            insert dbo.trackinginfo_ values(@schedule_date, @employee1, @work_area,null,null,null,null,null, null, null,@ccname,null, @hours1, 0.0, @hours1,0.0);     end end 

i using cmd.executescalar() insert new values asp.net application. after each insert trigger inserting additional 7 rows of data employee null. query execution not present inside loop. how possible?

i'm not sure problem trigger is, not programmed correctly. assuming inserted contains 1 row, , not correct.

perhaps want trigger this:

    insert dbo.trackinginfo_         select employee, work_area, null, null, null ,null, null, null, null,                cc.name, null, hours, 0.0, hours1, 0.0         inserted join              workarea_ w               on w.workareaname = i.work_area join              costcenter_ cc              on w.costcenterid = cc.id          employee not null; 

i recommend list columns explicitly in insert well.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -