IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_delete_employee]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_delete_employee]
GO
create proc [dbo].[mps_delete_employee]
@cmpid int,
@cuid int
as 
begin
    set nocount on
declare @wsid int = 100
select @wsid = jb_wsid from mps_job where jb_cuid = @cuid and jb_wsid = 0
if @wsid > 0 --工作完成
begin
delete from mps_login where cu_id = @cuid
delete from mps_login_role where lgu_cuid = @cuid
update mps_employee set cu_use =1,cu_code=cu_code+'(X)'+convert(varchar(200),getdate(),21),cu_account=cu_account+'(X)'+convert(varchar(200),getdate(),21),cu_status='离职' where cu_id = @cuid

end else --有未完成的工作
begin
select 'error' error,'该员工存在未完成的业务，无法删除' errorinfo
end

set nocount off
end