IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_delete_loginrole]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_delete_loginrole]
GO
-- =============================================  
-- Author: <Author,,Name>  
-- Create date: <Create Date,,>  
-- Description: <Description,,>  
-- =============================================  
CREATE procedure [dbo].[mps_delete_loginrole]  
@lgu_id INT,  
@lgu_cuid INT  
AS  
BEGIN  
SET NOCOUNT ON;  
DECLARE @count INT  
--删除数据  
DELETE FROM mps_login_role WHERE lgu_id=@lgu_id  
--查询数据的条数,需要保证的是employee中的那条数据始终存在  
/*SELECT @count = COUNT(*)   
FROM mps_login_role,mps_employee   
WHERE lgu_cuid=@lgu_cuid   
and cu_id=lgu_cuid   
and cu_bcid=lgu_bcid   
and cu_dpid=lgu_dpid   
and cu_otid=lgu_otid   
and cu_function=lgu_function  
and cu_otlevel = lgu_otlevel  
and cu_managelevel = lgu_managelevel  
and cu_professionlevel = lgu_professionlevel  
--如果不存在employee表中的角色,则添加一条记录  
IF(@count=0)  
BEGIN  
INSERT INTO mps_login_role(lgu_cuid,lgu_name,lgu_bcid,lgu_branch,lgu_dpid,lgu_depart,lgu_otid,lgu_title,lgu_function,lgu_otlevel,lgu_managelevel,lgu_professionlevel)  
SELECT cu_id,cu_name,cu_bcid,cu_branch,cu_dpid,cu_depart,cu_otid,cu_title,cu_function,cu_otlevel,cu_managelevel,cu_professionlevel  
FROM mps_employee  
where cu_id=@lgu_cuid  
select * from mps_login_role where lgu_id=@@IDENTITY  
END  
--防止继续使用被删除的角色进行登录  
update mps_login   
set cu_bcid=b.cu_bcid,cu_branch=b.cu_branch,  
cu_dpid=b.cu_dpid,cu_depart=b.cu_depart,  
cu_function=b.cu_function,  
cu_otid=b.cu_otid,cu_title=b.cu_title,  
cu_otlevel=b.cu_otlevel,  
cu_managelevel=b.cu_managelevel,  
cu_professionlevel=b.cu_professionlevel  
from mps_employee b  
where mps_login.cu_objid=@lgu_cuid and cu_type=0  
update mps_login_role set lgu_branch='集团总部' where lgu_bcid=0*/  
END