How do you do pagination in sql server 2008 ?
+5
A:
You can use ROW_NUMBER() e.g.
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;
AdaTheDev
2010-02-11 12:27:05
+3
A:
You can try something like
DECLARE @Table TABLE(
Val VARCHAR(50)
)
DECLARE @PageSize INT,
@Page INT
SELECT @PageSize = 10,
@Page = 2
;WITH PageNumbers AS(
SELECT Val,
ROW_NUMBER() OVER(ORDER BY Val) ID
FROM @Table
)
SELECT *
FROM PageNumbers
WHERE ID BETWEEN ((@Page - 1) * @PageSize + 1)
AND (@Page * @PageSize)
astander
2010-02-11 12:28:48
+1 Excellent article.
Walter
2010-02-11 12:49:24
+1
A:
These two articles contain the information which I found useful some time ago:
http://www.asp101.com/articles/gal/effectivepaging/default.asp, http://aspnet.4guysfromrolla.com/articles/031506-1.aspx
Roman Boiko
2010-02-11 12:39:35