IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_worktime_update]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_worktime_update]
GO

   
 
CREATE trigger [dbo].[mps_worktime_update] on [dbo].mps_worktime for update as
begin
   declare
      @maxcard  int,
      @ins_accop_id bigint,
      @del_accop_id bigint,
      @numrows  int,
      @numnull  int,
      @errno    int,
      @errmsg   varchar(255)

      select  @numrows = @@rowcount
      if @numrows = 0
         return

      declare @cmpid int 
      select top 1 @cmpid=wt_cmpid from inserted 
      exec mps_gen_calc_worktime  @cmpid 

      return

/*  Errors handling  */
error:
    -- raiserror @errno @errmsg
    rollback  transaction
end