设置游标与游标变量的关联

leong_dongzi 2012-05-02 05:23:11
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月份出生的学生信息。
...全文
230 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
leong_dongzi 2012-05-08
  • 打赏
  • 举报
回复
declare @stu_c cursor
set @stu_c=stu_cursor
declare @stu_id char(4),@stu_name char(8),@stu_sex char(2),@stu_bdate datetime,
@address varchar(50),@remark varchar(50),@stu_depa nchar(1)
open @stu_c
fetch next from @stu_c into @stu_id,@stu_name,@stu_sex,@stu_bdate,@address,@remark,@stu_depa
while @@FETCH_STATUS=0
begin
select @stu_id as 学号,@stu_name as 姓名,@stu_sex as 性别,@stu_bdate as 出生日期,
@address as 家庭地址,@remark as 备注,@stu_depa as 院系
where month(@stu_bdate)>=6 and month(@stu_bdate)<=9
fetch next from @stu_c into @stu_id,@stu_name,@stu_sex,@stu_bdate,@address,@remark,@stu_depa
end
close @stu_c
deallocate @stu_c
go
使用游标查询,这样才是对的,终于知道了
leong_dongzi 2012-05-02
  • 打赏
  • 举报
回复
结果还是一样的,这个办法不行[Quote=引用 1 楼 的回复:]

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 *……
[/Quote]
了解 2012-05-02
  • 打赏
  • 举报
回复
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

全选,在执行试试。

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧