--创建游标
declare DataPoint cursor
--读取部门表下级编号的数据
for select b_PriorID_i,b_Name_c,b_StaffOfDep from b_Hand where b_PriorID_i>@ID
--打开游标
open DataPoint
--读取值到
fetch next from DataPoint into @PriorID,@GetName,@HandName
while @@FETCH_STATUS=0
begin
--set @sql= N'select @BuMenNames=b_StaffOfDep,@PeopleNames=b_Name_c from b_Hand where b_PriorID_i='+CAST(@PriorID AS varchar(10))
--exec sp_executesql @sql,N'@BuMenNames varchar(50) out,@PeopleNames varchar(50) out',@HandName out,@GetName out
--将数据封装到临时表里面
insert into #HandInfo values(@PriorID,@GetName,@HandName)
--读取下一行值
fetch next from DataPoint into @PriorID,@GetName,@HandName
end
--关闭游标
close DataPoint
--释放对象
deallocate DataPoint
select * from #HandInfo
declare DataPoint cursor
--读取部门表下级编号的数据
for select b_PriorID_i,b_Name_c,b_StaffOfDep from b_Hand where b_PriorID_i>@ID
--打开游标
open DataPoint
--读取值到
fetch next from DataPoint into @PriorID,@GetName,@HandName
while @@FETCH_STATUS=0
begin
--set @sql= N'select @BuMenNames=b_StaffOfDep,@PeopleNames=b_Name_c from b_Hand where b_PriorID_i='+CAST(@PriorID AS varchar(10))
--exec sp_executesql @sql,N'@BuMenNames varchar(50) out,@PeopleNames varchar(50) out',@HandName out,@GetName out
--将数据封装到临时表里面
insert into #HandInfo values(@PriorID,@GetName,@HandName)
--读取下一行值
fetch next from DataPoint into @PriorID,@GetName,@HandName
end
--关闭游标
close DataPoint
--释放对象
deallocate DataPoint
select * from #HandInfo