Pages

Jun 11, 2008

How to select middle rows using CTE in SQL2005

CTE Common Table Expression are used for custom paging in asp.net
Gets the row number from the number of IDs present in the table
WITH ItemCTE AS

(
SELECT *, (ROW_NUMBER() OVER( ORDER BY ID)) as RowID FROM tablename
)

-- each CTE should be followed by an select statement
SELECT * FROM ItemCTE WHERE RowID BETWEEN 11 AND 20

No comments: