日期:2014-05-18  浏览次数:20527 次

设置游标与游标变量的关联
[code=SQL][/code]declare @stu_c cursor 
declare stu_cursor cursor
for 
select * from student_info where 性别='男'
set @stu_c=stu_cursor
open @stu_c
fetch next from @stu_c 
while @@FETCH_STATUS=0
begin 
select * from student_info where 
month(出生日期)>=6 and month(出生日期)<=9
fetch next from @stu_c 
end
close @stu_c
第五行提示stu_cursor“列名无效”,为什么会这样呢?
实验要求是这样的:声明游标变量@stu_c,使之关联stu_cursor游标,利用@stu_c查询出生日期在6~9月份出生的学生信息。

------解决方案--------------------
declare @stu_c cursor
declare stu_cursor cursor for select * from student_info where 性别='男'
set @stu_c=stu_cursor
open @stu_c
fetch next from @stu_c
while @@FETCH_STATUS=0
begin
select * from student_info where month(出生日期)>=6 and month(出生日期)<=9
fetch next from @stu_c
end
close @stu_c
DEALLOCATE stu_cursor

全选,在执行试试。