create procedure proc_dept
as
declare @cursor cursor,
@id varchar(50),
@pid varchar(100)
begin
set @cursor = cursor
for
select deparet_id, parent_deparet_id from dbo.tb_department_tree order by sequence;
open @cursor
fetch next from @cursor into @id, @pid;
while(@@FETCH_STATUS = 0)
begin
if(@pid is null)
begin
update tb_department_tree set scope = @id, tlevel = 1, tpath = @id where deparet_id = @id;
end
else
begin
update tb_department_tree set tlevel = (select tlevel from tb_department_tree where deparet_id = @pid)+1, tpath = (select tpath from tb_department_tree where deparet_id = @pid)+'-'+@id where deparet_id = @id;
update tb_department_tree set scope =(select SUBSTRING(tpath, 0, CHARINDEX('-',tpath, 0)) from tb_department_tree where deparet_id = @id) from tb_department_tree where deparet_id = @id;
end;
fetch next from @cursor into @id, @pid;
end;
close @cursor;
end;
exec proc_dept;
drop procedure proc_dept;
用户登录
还没有账号?立即注册
用户注册
投稿取消
| 文章分类: |
|
还能输入300字
上传中....
逝去的快乐呢