现在的位置: 首页 > 综合 > 正文

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

2012年01月23日 ⁄ 综合 ⁄ 共 488字 ⁄ 字号 评论关闭

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()

抱歉!评论已关闭.