Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Paginate results from a T-SQL query
DECLARE @pageNo INT
DECLARE @pageSize INT
SET @pageNo = 2
SET @pageSize = 15
SELECT
CustomerNo,
FirstName,
LastName
FROM
(
SELECT
(ROW_NUMBER() OVER (ORDER BY LastName, FirstName)) - 1 as RowNum,
*
FROM tCustomer
) temp1
WHERE temp1.RowNum BETWEEN (@pageNo * @pageSize) AND ((@pageNo + 1) * @pageSize - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.