use esda
go
---------------------------------------------------------------------------
select * from jg
delete from jg;
---------------------------------------------------------------------------
declare mycursor cursor for
select group_name,parent_id from user_group
open mycursor
declare @field_name varchar(100)
declare @parent_id varchar(100)
declare @jg_id varchar(100)
declare @jg_xh varchar(100)
declare @bm_id varchar(100)
declare @bm_xh varchar(100)
declare @a_jgid varchar(100)
declare @b_jgxh varchar(100)
fetch next from mycursor into @field_name,@parent_id
begin
while(@@fetch_status=0)
begin
--set @parent_id = (select parent_id from user_group)
set @JG_ID = (select max(JG_ID)+1 as JG_ID from jg)
set @JG_XH = (select max(JG_XH)+1 as JG_XH from jg)
set @BM_ID = (select max(BM_ID)+1 as JG_XH from jg)
set @BM_XH = (select max(BM_XH)+1 as JG_XH from jg)
if @parent_id = 'D069399021CF4AED8F29C34CA0989EAC'
begin
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', 0, ' ', 1, 0,'', 0, '1')
end
else if @parent_id = '9FFE560ACA7849E48D1A28DDDF06FC85'
begin
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @JG_ID, @field_name, @JG_XH, 0, '', 0, '1')
end
else if @parent_id = 'F1F8509862BE4FAD950480A18786EF87'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '公司总部')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '公司总部')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '公司总部', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
else if @parent_id = '00665C7EC76C462E97884657C8CEA877'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '项目经理部')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '项目经理部')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '项目经理部', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
fetch next from mycursor into @field_name,@parent_id
end
end
close mycursor
deallocate mycursor
select * from jg order by jg_id, bm_id
select * from user_group
----------------------------------------------------------------------------------------
else if @parent_id = 'A8EBA01C107D4897972D82532C88A3B7'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '分公司')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '分公司')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '分公司', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
else if @parent_id = 'BEE8EEC9B3CC463A848F711DB45D6B4F'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '控股公司')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '控股公司')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '控股公司', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
else if @parent_id = 'B4BA33D99BAE435AA8E6C27B172483B5'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '区域公司')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '区域公司')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '区域公司', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
else if @parent_id = 'B45F27EAD94D4D6B8E5E2693B8AC3D3E'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '关联单位')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '关联单位')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '关联单位', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
else if @parent_id = 'D74D75BAE66C43AA94B7E56462B95A6A'
begin
set @a_jgid = (select top 1 jg_id from jg where jg_name = '参股公司')
set @b_jgxh = (select top 1 jg_xh from jg where jg_name = '参股公司')
insert into jg(RE, JG_ID, JG_NAME, JG_XH, BM_ID, BM_NAME, BM_XH, QZH_ID)
values ('', @a_jgid, '参股公司', @b_jgxh, @BM_ID, @field_name, @BM_XH, '1')
end
------------------------------------------------------------------------------------------------