2002070344 发表于 2009-1-11 14:16

使用游标update为什么不能用order by?

大家好
我使用游标来修改数据
发现select中有order by 语句的话,会提示游标是只读的
搜索了一下,说拿掉order by就好了,但没说原因
请问是什么原因?

sql是这样写的:

declare test cursor for
select id,hshf_id from gwh where (id isnull) and (hshf_id is not null) and (nianfen='2008') '这里再加order by就会报错
open test
declare @idno int, @idno1 int
fetch next from test
into @idno,@idno1
while(@@fetch_status=0)
begin
if(@idno1<370 and @idno1>0)
update gwh set id = hshf_id +5000
where current of test
fetch next from test
into @idno,@idno1
end
close test
deallocate test

bcde633 发表于 2009-1-21 16:55

hmily 发表于 2009-2-15 11:48

有order by 一样可以的,应该是你的表没有建主建的原因。
页: [1]
查看完整版本: 使用游标update为什么不能用order by?