Search This Blog

Saturday, June 5, 2010

Paging in SqlServer

Paging in SQL Server with ROW_NUMBER()


SELECT  *
FROM     (SELECT  ROW_NUMBER() OVER (ORDER BY iCagegoryID DESC)
             AS Row,sCategoryName, sCategoryType FROM CategoryMaster)
            AS LogWithRowNumbers
WHERE  Row >= 11 AND Row <= 20

See the example above. It tells that on which column you want to do paging, it stores column's index.
In above example "iCategoryID" column's Index store in variavle "Row" and everytime just user has to pass extra 2 variables minvalue and maxvalue through which we can get those much of records displayed in 1 page.

No comments:

Post a Comment