Thursday, 26 July 2012

Custom paging in SQL Server


CREATE PROCEDURE [ProcedureName]
(
    @CurrentIndex int,
    @PageSize int
)
AS

SELECT * FROM(
          SELECT ROW_NUMBER() over(order by ProductID) AS RowId,
                     Product_Name
          FROM    Products
    )a
WHERE RowId BETWEEN (@CurrentIndex -1) * @TotalPageSize+ 1
                      AND     (@CurrentIndex  * @TotalPageSize )

No comments:

Post a comment