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

CREATE trigger [dbo].[mps_flowworkstatus_update] on dbo.mps_flowworkstatus for update as
begin
    declare
       @maxcard  int,
       @numrows  int,
       @numnull  int,
       @errno    int,
       @errmsg   varchar(255)

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

 update mps_tableupdated set tu_updated=0 where  tu_table='mps_flowwork'
update mps_flowwork set wrk_changed = 0  from inserted where ws_swrkid=wrk_id and wrk_changed=1 

    return

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