编程论坛's Archiver

yxpke 发表于 2008-1-12 11:23

请帮忙解决游标问题

DECLARE @a int,@b int
DECLARE abc  CURSOR FOR
SELECT roomno,sitno FROM aa  where xxcode=@xxcode and nj_c=@nj_c  order by randshu --带有order by
--出错,提示游标是 READ ONLY 的。语句已终止。没有order by 则正常,但我要对随机数据进行排序来编排,请帮忙
--for update of roomno,sitno
OPEN abc
FETCH NEXT FROM abc
select  @a=1,@b=0
WHILE (@@FETCH_STATUS = 0)
begin
   begin
       if @b>=@shu
          select @a=@a+1,  @b=0,@b=@b+1
      else
         set @b=@b+1
    end
       update aa set roomno=@a,sitno=@b   where current of abc
      FETCH NEXT FROM abc
end
     CLOSE abc
    DEALLOCATE abc
GO

yxpke 发表于 2008-1-12 17:23

判断之处有问题,已解决了

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.