Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do pagination in SQL Server 2008

How do you do pagination in SQL Server 2008 ?

like image 211
Omu Avatar asked Feb 11 '10 12:02

Omu


1 Answers

You can use ROW_NUMBER():

Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.

Example:

WITH CTEResults AS (     SELECT IDColumn, SomeField, DateField, ROW_NUMBER() OVER (ORDER BY DateField) AS RowNum     FROM MyTable )  SELECT *  FROM CTEResults WHERE RowNum BETWEEN 10 AND 20; 
like image 155
AdaTheDev Avatar answered Sep 21 '22 09:09

AdaTheDev