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/archive/2008/10/20/1315041.html

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐