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

   

CREATE trigger [dbo].[mps_flowwork_insert] on [dbo].[mps_flowwork] for insert as
begin
    declare
       @maxcard  int,
       @numrows  int,
       @numnull  int,
       @errno    int,
       @errmsg   varchar(255)

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

declare @cmpid int 
select top 1 @cmpid = biz_cmpid from  inserted  , mps_biztype where wrk_bizid=biz_id 
set @cmpid = isnull(@cmpid,0) 

      update mps_tableupdated set tu_updated=0 where tu_table='mps_flowwork'    and tu_cmpid=@cmpid  
  update mps_biztype set biz_changed = 0  from inserted where wrk_bizid=biz_id and biz_changed=1 
 
    return

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