IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_change_loginrole]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_change_loginrole]
GO

-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
CREATE procedure [dbo].[mps_change_loginrole] 
@lgu_id INT,
@lgu_cuid INT,
@cu_loginid INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @bcid INT
DECLARE @dpid INT
DECLARE @otid INT
DECLARE @otlevel INT
DECLARE @tglevel INT
DECLARE @mglevel INT
DECLARE @branch VARCHAR(50)
DECLARE @depart VARCHAR(50)
DECLARE @title VARCHAR(50) --岗位
DECLARE @function INT      --角色

--获取对应角色的信息
SELECT @bcid = lgu_bcid,
   @branch = lgu_branch,
   @dpid = lgu_dpid,
   @depart = lgu_depart,
   @otid = lgu_otid,
   @title = lgu_title,
   @function = lgu_function,
   @otlevel = lgu_otlevel,
   @tglevel = lgu_professionlevel,
   @mglevel = lgu_managelevel
FROM mps_login_role
WHERE lgu_id = @lgu_id AND lgu_cuid=@lgu_cuid
--导入数据
IF(@branch is not null)
BEGIN
UPDATE mps_login
SET cu_bcid=@bcid,
cu_branch=@branch,
cu_dpid=@dpid,
cu_depart=@depart,
cu_otid=@otid,
cu_title=@title,
cu_function=@function,
cu_otlevel=@otlevel,
cu_professionlevel=@tglevel,
cu_managelevel=@mglevel
WHERE cu_objid=@lgu_cuid and cu_type=0
END
--返回登录表中的最新数据
select * from mps_login where cu_id = @cu_loginid
END