sql - Trigger sometimes not firing on Update and Inserted -
i have 2 tables
first table listexecutionaction consists of no. of actions. structrue of table follows
queueid actionid executed 135 44 1 135 45 1 135 46 1 135 47 1 135 48 1
second table listqueue consists of summary of total actions done. construction follows
ddbmskey noofactivities completed 135 5 3
my requirement every insert , update on listexecutionaction table should calculate noofactivities , no. of actions completed. wrote trigger on table on listexecutionaction follows.
alter trigger [common].[activitystatus_afterinsertupdate] on [common].[listexecutionaction] after insert,update begin update common.listqueue set noofactivities= (select count(id) common.listexecutionaction queueid=lstact.queueid), completed= (select count(id) common.listexecutionaction queueid=lstact.queueid , executed=1) common.listqueue lstqueue left bring together common.listexecutionaction lstact on lstqueue.ddbmskey= lstact.queueid lstqueue.ddbmskey in (select queueid inserted) end
my desired output table listqueue should follows
ddbmskey noofactivities completed 135 5 5
but trigger calculating wrong result in no. of actions completed , giving result as
ddbmskey noofactivities completed 135 5 3
please suggest wrong in trigger. works fine , fails sometime. want trigger on both insert , update
it seems query can simplified this:
alter trigger [common].[activitystatus_afterinsertupdate] on [common].[listexecutionaction] after insert,update begin update common.listqueue set noofactivities= (select count(id) common.listexecutionaction queueid=lstact.queueid), completed= (select count(id) common.listexecutionaction queueid=lstact.queueid , executed=1) lstqueue.ddbmskey in (select queueid inserted) end
i don't think solve problem, @ to the lowest degree query shorter.
sql triggers
No comments:
Post a Comment