Tuesday, August 26, 2008

Use of Row_Number function for custom paging

The Row_Number() function in SQL is used to assign sequence number for each record retrieved for a collection of records.

Hence, we can use this function to retrieve a portion of records (Custom) from the collection of records.
Syntax:

SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY [Field Used for Sorting])AS Row, * FROM ([Select Query])AS UserQuery) AS SelectionWithRowNumbers WHERE Row >[First Record]AND Row<=[Last Record]

No comments: