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

   
 
CREATE trigger [dbo].[mps_employee_subusers_insert] on [dbo].[mps_employee_subusers] for insert as
begin
    declare
       @numrows  int,
       @errno    int,
       @errmsg   varchar(255)

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

    
declare @cmpid int 
select top 1 @cmpid = cu_cmpid from  inserted  , mps_login where cs_cuid=cu_id 
set @cmpid = isnull(@cmpid,0) 
    
update mps_tableupdated set tu_updated=0 where tu_table='mps_employee'  and tu_cmpid=@cmpid

    return

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