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

CREATE proc [dbo].[mps_generate_loginrole_source]
(@cmpid int)
as
begin
set nocount on
declare @source varchar(max)
--分公司 t1
set @source='集团总部=0|'
select @source+=bc_display+'='+convert(varchar,bc_id)+'|' from mps_branch where bc_cmpid=@cmpid
select @source as  source
--部门 t2
select dp_id,dp_depart,dp_bcid from mps_depart where dp_cmpid=@cmpid and dp_isdepart=0 
--职位 t3
select ot_id,ot_title,dt_dpid from mps_title,mps_depart_title where ot_id=dt_otid and ot_cmpid=@cmpid
--角色 t4
set @source=''
select @source+=rl_title+'='+convert(varchar,rl_value)+'|' from mps_role where rl_cmpid=@cmpid

select @source as  source
--职位等级 t5
set @source=''
select @source+=tg_caption+'='+convert(varchar,tg_grade)+'|' from mps_title_grade where tg_cmpid=@cmpid

select @source as  source
--管理等级 t6
set @source=''
select @source+=mg_caption+'='+convert(varchar,mg_grade)+'|' from mps_manage_grade where mg_cmpid=@cmpid

select @source as  source
--专业等级 t7
set @source=''
select @source+=bg_caption+'='+convert(varchar,bg_grade)+'|' from mps_profession_grade where bg_cmpid=@cmpid
select @source as  source
end