drop table rkpc
GOcreate table rkpc(id int, name varchar(10), idnum int,户主 varchar(10))
insert into rkpc values(1 , '张三' , 434300 ,null)
insert into rkpc values(2 , '张三老婆', null ,null)
insert into rkpc values(3 , '张三女儿', null ,null)
insert into rkpc values(4 , '李四' , 434311 ,null)
insert into rkpc values(5 , '李四老婆', null ,null)
insert into rkpc values(6 , '李四儿子', null ,null)
godeclare @id int,@idnum char(30)
declare cur cursor fast_forward for
select id,idnum from rkpc;
fetch next from cur into @id,@idnum
while @@FETCH_STATUS=0
open cur
beginif @idnum IS NOT NULLbegin
update rkpc set 户主='是'
where id=@id
end
elsebegin
update rkpc set 户主='否'
where id=@id;
end
fetch next from cur into @id,@idnum;
endclose cur
deallocate cur
我在第九行加了@就出现这个错误
服务器: 消息 16917,级别 16,状态 2,行 4
游标未打开。(所影响的行数为 0 行)服务器: 消息 16917,级别 16,状态 2,行 21
游标未打开。
服务器: 消息 16917,级别 16,状态 1,行 24
游标未打开。第九行不加@,出现这个错误服务器: 消息 207,级别 16,状态 3,行 9
列名 'idnum' 无效。
不知道是怎么回事 我怎么查也查不出来哪儿错了很是郁闷!!还真没有查出来哪儿错了!!
GOcreate table rkpc(id int, name varchar(10), idnum int,户主 varchar(10))
insert into rkpc values(1 , '张三' , 434300 ,null)
insert into rkpc values(2 , '张三老婆', null ,null)
insert into rkpc values(3 , '张三女儿', null ,null)
insert into rkpc values(4 , '李四' , 434311 ,null)
insert into rkpc values(5 , '李四老婆', null ,null)
insert into rkpc values(6 , '李四儿子', null ,null)
godeclare @id int,@idnum char(30)
declare cur cursor fast_forward for
select id,idnum from rkpc;
fetch next from cur into @id,@idnum
while @@FETCH_STATUS=0
open cur
beginif @idnum IS NOT NULLbegin
update rkpc set 户主='是'
where id=@id
end
elsebegin
update rkpc set 户主='否'
where id=@id;
end
fetch next from cur into @id,@idnum;
endclose cur
deallocate cur
我在第九行加了@就出现这个错误
服务器: 消息 16917,级别 16,状态 2,行 4
游标未打开。(所影响的行数为 0 行)服务器: 消息 16917,级别 16,状态 2,行 21
游标未打开。
服务器: 消息 16917,级别 16,状态 1,行 24
游标未打开。第九行不加@,出现这个错误服务器: 消息 207,级别 16,状态 3,行 9
列名 'idnum' 无效。
不知道是怎么回事 我怎么查也查不出来哪儿错了很是郁闷!!还真没有查出来哪儿错了!!
解决方案 »
- grant
- 关于SQL SERVER 2005用户对象的问题
- 求助:计算机名修改后,sql server 2005不能连接
- 急~~!请问怎么设置SQL的日志??
- 问个比较日期大小的问题~~~~
- 帮忙分析下这段代码
- “错误14294:请提供@job_id或@job_name来标识作业”
- 关于视图是否可以提高查询效率?
- csdn的网管向法挺多,什么不让up,gz了,现在又不让连续发3次言,解决这个问题好像还真有点难度,可见网管的智慧,但是为什么他不想一想,难道一个人只能有一个账号吗?又可见网管的智慧
- 一个Primary key 的问题!
- 求SQL语句,得到一下结果
- 单条数据对应多个日期都是怎么存储的?
放到fetch前面
open cur
fetch next from cur into @id,@idnum
while @@FETCH_STATUS=0beginif @idnum IS NOT NULLbegin
update rkpc set 户主='是'
where id=@id
end
elsebegin
update rkpc set 户主='否'
where id=@id;
end
fetch next from cur into @id,@idnum;
endclose cur
deallocate cur
insert into rkpc values(1 , '张三' , 434300 ,null)
insert into rkpc values(2 , '张三老婆', null ,null)
insert into rkpc values(3 , '张三女儿', null ,null)
insert into rkpc values(4 , '李四' , 434311 ,null)
insert into rkpc values(5 , '李四老婆', null ,null)
insert into rkpc values(6 , '李四儿子', null ,null)
declare @id int,@idnum char(30)
declare cur cursor fast_forward for
select id,idnum from rkpc;
open cur
fetch next from cur into @id,@idnum
while @@FETCH_STATUS=0
beginif @idnum IS NOT NULLbegin
update rkpc set 户主='是'
where id=@id
end
elsebegin
update rkpc set 户主='否'
where id=@id;
end
fetch next from cur into @id,@idnum;
endclose cur
deallocate cur
update rkpc set 户主 case when idnum IS NOT NULL then '是'
else '否' end
while @@FETCH_STATUS=0
open cur调整为:
open cur ---先打开游标才能读取
fetch next from cur into @id,@idnum
while @@FETCH_STATUS=0