查询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为表具有唯一值的任何字段

解决方案 »

  1.   

    select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
    select top M-N * from #temptable where iid>=N
      

  2.   

    select identity(int,1,1) as F0,* into #temp from tablename
    select top m-n * from #temp where F0>=n
      

  3.   

    排序后选出第30-50条记录
    1) select * from (select top 50 * from table order by id) a where id not in (select top 29 id from table order by id)2) select top 20 * from #temp where id not in (select top 29 id from #temp)
      

  4.   

    SELECT * FROM tablename不可取
    一次将所有的记录返回前台
    网络资源/几服务器资源站用太大
      

  5.   

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

  6.   

    取出第10条到第20条1.
    select top (20-10) * from tableName where 关键字段 not in (select top 10 关键字段 from tableName)2.
    select top (20-10+1) * from (select top 20 * from tableName order by 关键字段 desc) order by 关键字段
      

  7.   

    /*
    用存储过程实现的分页程序
    */
    CREATE procedure Department_pagination 
    @SelectStr nvarchar(1000),
    @ColumnStr nvarchar (1000),
    @OrderStr nvarchar (1000),
    @CurrentPage int,
    @PageCount int
    as
    declare @TimeName nvarchar(25)
    declare @TableStr nvarchar(1000)select @TimeName = convert(nvarchar(23), getdate(), 121)
    set @TimeName = REPLACE(@TimeName, '.', '')
    set @TimeName = REPLACE(@TimeName, ':', '')
    set @TimeName = REPLACE(@TimeName, '-', '')
    set @TimeName = REPLACE(@TimeName, ' ', '')select @TableStr='create table ##Tab' + @TimeName + '(wb int identity,'
    exec(@TableStr+@ColumnStr+')')
    exec('insert into ##Tab' + @TimeName + ' ' + @SelectStr + ' order by ' + @OrderStr)
    exec('select * from ##Tab' + @TimeName + ' where wb between ((' + @CurrentPage + '-1)*' + @PageCount + '+1) and ' + @CurrentPage + '*' + @PageCount + ' order by wb')
    exec('drop table ##Tab' + @TimeName)
    GO参数1:select语句。2:字段列表。3:排序字段。4:当前页。5每页数目
      

  8.   

    这个最快:CREATE PROCEDURE GetProductsPaged
    @lastProductID int,
    @pageSize int
    AS
    SET ROWCOUNT @pageSize
    SELECT *
    FROM Products
    WHERE [standard search criteria]
    AND ProductID > @lastProductID
    ORDER BY [Criteria that leaves ProductID monotonically increasing]
    GO
      

  9.   

    高手呀.不会都是专业地数据库程序员吧.   我只是在JSP里用一用简单地查询. 基本上在解决了我提地问题.3万条记录地速度可以接收.我地实现是使用jsp分页,不过原来地性能瓶颈在于我地结果集太大.
       太难的解答我看不懂.不过谢谢各位了.
       结贴!