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

解决方案 »

  1.   

    CREATE PROCEDURE Get_Customers_By_Page
    @CurrentPage int,
    @PageSize int,
    @TotalRecords int output
    asSELECT identity(int,1,1) as id ,* into  #TempTable from tableDECLARE @FirstRec int, @LastRec int
    SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
    SELECT @LastRec = (@CurrentPage * @PageSize + 1)SELECT 
      *
    FROM 
      #TempTable
    WHERE 
      ID > @FirstRec 
    AND
      ID < @LastRecSELECT @TotalRecords = COUNT(*) FROM table
      

  2.   

    我需要接收where 子句构造的查询条件,而不是单纯取出所有记录
      

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