Pagination call

How to read certain page from SQL table

Originally from
from http://social.technet.microsoft.com/wiki/contents/articles/23811.paging-a-query-with-sql-server.aspx

-- Viewing Page 4 of 12 rows per page
SELECT * FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID) AS RowNUMBER, * FROM ANmars_User.IQNames_EN) AS TBL WHERE RowNUMBER BETWEEN ((4 - 1) * 12 + 1) AND (4 * 12) ORDER BY ID

-- VIEWING PAGE 2 WITH 5 ROWS
DECLARE @PageNumber AS INT, @RowspPage AS INT
SET @PageNumber = 2
SET @RowspPage = 5
SELECT * FROM (
 SELECT ROW_NUMBER() OVER(ORDER BY ID_EXAMPLE) AS NUMBER,
 ID_EXAMPLE, NM_EXAMPLE, DT_CREATE FROM TB_EXAMPLE
 ) AS TBL
 WHERE NUMBER BETWEEN ((@PageNumber - 1) * @RowspPage + 1) AND (@PageNumber * @RowspPage)
 ORDER BY ID_EXAMPLE

Views 348 Downloads 129

'SQL', 'Pagination', 'Pages', 'rows per page'

ANmarAmdeen
324
Layout+Design SQL
Revisions

v1.0