游标嵌套

李永波 发布于 2010/08/05 16:09
阅读 99
收藏 2

Declare @id varchar(500);
Declare @rid varchar(500);
declare @Tsql varchar(1000);
declare Cur cursor for
Select top 10 Expfunction,Resume_id from Resume
open cur
fetch next from cur into @id,@rid
while @@fetch_status =0
begin

declare @tname varchar(300);
declare @name varchar(500);
set @name='';

set @Tsql= 'declare Cur2 cursor for select [name] from funtype where id in (@id)+''')';
print(@tsql)

exec(@tsql) 

-- declare Cur2 cursor for 

--select [name] from funtype where id in (@id)

-- declare Cur2 cursor for 

--exec('select [name] from funtype where id in (+@id+)')

open Cur2
fetch next from cur2 into @tname
while (@@fetch_status =0)
begin
set @name=@name+','+@tname ;
fetch next from cur2 into @tname
end
set @name = substring(@name,2,len(@name)-1)

print(@name)

--print(@id)
Close Cur2
Deallocate Cur2

--exec(@Tsql)
Fetch Next From Cur Into @id,@rid
End
Close Cur
Deallocate Cur


 按照删除线部分不能得到正确结果

按照斜体部分 不能运行 报错

 

加载中
返回顶部
顶部