sql 中用游标查询出当前的值赋值给一个变量?

来源:百度知道 编辑:UC知道 时间:2024/05/25 09:24:58
我想查询游标当前所指向的值,并把它的值赋值给我以及声明好的一个变量,请问要怎么做?
set @专业代号名称= (select 专业名称 from dbo.数据总表 where current of mycursor group by 专业名称 )
@专业代号名称 是我在前面定义好的
我定义的都是 varchar(50 ) 的类型···在线等·急呀··求求各位大虾了··
declare mycursor cursor for select 专业名称 from dbo.数据总表 where 毕业时间='20080701' group by 专业名称
set @count=(select count(*) from (select 专业名称 from dbo.数据总表 where 毕业时间='20080701' group by 专业名称) temp)
open mycursor
fetch next from mycursor into @专业代号名称
while(@@fetch_status=0 and @i<=@count)
begin
--set @专业代号名称= (select 专业名称 from dbo.数据总表 where current of mycursor group by 专业名称 )
--print @专业代号名称
set @sum=(select count(*) from dbo.数据总表 where 专业名称='@专业代号名称' and 毕业时间='20080701')
现在主要问题是@专业代号名称' 这没有反应,就像没有一样

declare @专业代码名称 varchar(50)
declare cur_test cursor for select 专业名称 from dbo.数据总表 where 条件 group by 专业名称
open cur_test
fetch cur_test into @专业代码名称
while(@@fetch_status = 0)
begin
--这里是你自己要做的操作内容。比如查询变量值
select @专业代码名称

fetch next from cur_test into @专业代码名称
end
close cur_test
deallocate cur_test