sql server 2000使用游标和随机查询的脚本示例

declare c SCROLL cursor for

select id from Rows100000 order by id desc

open c

declare @Count as integer

declare @Str as varchar(1024)
declare @tmp as int

set @Count=80;

FETCH absolute 999 from c INTO @tmp

if @@FETCH_STATUS = 0

begin

set @Count=@Count-1

set @Str='';

set @Str=@Str+LTRIM(Str(@tmp))

end;

while (@@FETCH_STATUS = 0) and (@Count>0)
begin 
   
      FETCH NEXT FROM  c INTO @tmp

 if @@FETCH_STATUS = 0
 begin

  set @Str=@Str+','+LTRIM(Str(@tmp))
  
        set @Count=@Count-1

 end


end

close c

DEALLOCATE c

select @Str

select top 10 * from Rows100000 order by newid()

原文地址:https://www.cnblogs.com/MaxWoods/p/1315041.html