select IDENTITY(int, 1,1) AS ID_Num,* into #temp from 表
select * from #temp where ID_Num between 10 and 20

解决方案 »

  1.   

    declare @SQLStr varchar(8000)
    set @SQLStr='SELECT Top '+cast(@每页大小 as varchar)+' * FROM 表 WHERE 主键列 NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' 主键列 from 表 )'
    exec(@SQLStr)
      

  2.   

    知其然还要知其所以然,以下我替你总结了一下方法:如何取出第m条到第n条记录间的纪录?
    方法一:取出前n条和前m条然后取出其差(n-m)
    select top(n-m) * 
    from table
    where 关键字段 not in(select top m 关键字段 from table)方法二:先取出前n条的,再倒过来取出n-m就可以
    select top(n-m+1) * 
    from (select top n * from table order by 关键字段 desc)
    order by 关键字段
      

  3.   

    查询N-M条记录。
    select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
    select top M-N * from #temptable where iid>=NOR:select top M-N * from yourTable where id not in(select top N-1 id from table)
    ID为表具有唯一值的任何字段