Skip to content

Instantly share code, notes, and snippets.

@boocle
Last active October 18, 2018 09:26
Show Gist options
  • Save boocle/14701e2b196991b0fc180e98bf30a252 to your computer and use it in GitHub Desktop.
Save boocle/14701e2b196991b0fc180e98bf30a252 to your computer and use it in GitHub Desktop.
Pagination T-SQL
DECLARE @intStartRow int;
DECLARE @intEndRow int;
SET @intStartRow = (@intPage -1) * @intPageSize + 1;
SET @intEndRow = @intPage * @intPageSize;
WITH blogs AS
(SELECT strBlogName,
ROW_NUMBER() OVER(ORDER BY intID DESC) as intRow,
COUNT(intID) OVER() AS intTotalHits
FROM tblBlog)
SELECT strBlogName, intTotalHits FROM blogs
WHERE intRow BETWEEN @intStartRow AND @intEndRow
source : http://joelabrahamsson.com/my-favorite-way-to-do-paging-with-t-sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment