Created
December 10, 2016 18:24
-
-
Save tdittmar/185c125cbffa99061f58a5a2ae859766 to your computer and use it in GitHub Desktop.
Paginate results from a T-SQL query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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