问题在sql2000下
(代码简写)
SET ROWCOUNT 2
declare my_cursor cursor scroll dynamic
for
select serviceNo from services where IsRequest=0
open my_cursor
1.假设 services 表中有10条记录,为什么游标得到记录为10条,不为2。我明明SET ROWCOUNT 2 难道 SET ROWCOUNT 2 在游标下,无效!不明白快疯了
(代码简写)
SET ROWCOUNT 2
declare my_cursor cursor scroll dynamic
for
select serviceNo from services where IsRequest=0
open my_cursor
1.假设 services 表中有10条记录,为什么游标得到记录为10条,不为2。我明明SET ROWCOUNT 2 难道 SET ROWCOUNT 2 在游标下,无效!不明白快疯了
set @num 2
但是 select top @num from services where IsRequest=0 不可以,我才想到用 set ROWCOUNT 2 ,
现在 set @ROWCOUNT 2 在游标下又不可以!help me
我只要是获得指定的数据条数 ,比喻 services 表有 10条,我想获得2条.
我试过用 select top 2 from services where IsRequest=0 但是top 2又不能是变量
set @cnt=2;open c;
while @cnt>0
begin
fetch next from c;
if @@FETCH_STATUS<>0
break;
set @cnt=@cnt-1;
end
close c;
set @num=2
set @info=' '
set @info=@info+' declare my_cursor cursor scroll dynamic '
set @info=@info+' for '
set @info=@info+' select top '+cast(@num as varchar(10))+' serviceNo from services where IsRequest=0 '
set @info=@info+' open my_cursor '
set @info=@info+' declare @curServiceNo varchar(300) '
set @info=@info+' fetch next from my_cursor into @curServiceNo '
set @info=@info+' while(@@fetch_status=0) '
set @info=@info+' begin '
set @info=@info+' print @curServiceNo '
set @info=@info+' fetch next from my_cursor into @curServiceNo '
set @info=@info+' end '
set @info=@info+' close my_cursor '
set @info=@info+' deallocate my_cursor '
exec (@info)
xman_78tom 太多谢你了。我仲想在游标中,对services表的值,赋值给变量。能详细一点吗!
(逍遥游) 太感谢你了。