IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_employee_update]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_employee_update]
GO
create trigger [dbo].[mps_employee_update] on [dbo].[mps_employee] for update as
begin
insert into mps_sync(sk_type,sk_bizid,sk_tag2,sk_operation,sk_objid) 
   select 3,0,0,0,0 from deleted

    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 = cu_cmpid from  inserted  
set @cmpid = isnull(@cmpid,0) 

update mps_tableupdated set tu_updated=0 where tu_table='mps_employee'  and tu_cmpid=@cmpid  
            
delete d
from inserted s ,mps_login d
where d.cu_account = s.cu_account 
and d.cu_id = s.cu_id
and s.cu_use = 1

return

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