Skip to content

Instantly share code, notes, and snippets.

@dionnyprensa
Last active October 15, 2018 16:30
Show Gist options
  • Save dionnyprensa/4212a924455368a4055c121b0f7fab96 to your computer and use it in GitHub Desktop.
Save dionnyprensa/4212a924455368a4055c121b0f7fab96 to your computer and use it in GitHub Desktop.
Simple pager for sql server
CREATE PROCEDURE MyTablePagerSP
@Page INT = 1,
@SizePerPage INT = 100
AS
BEGIN
SET NOCOUNT ON:
SELECT FieldA, FieldB, FieldC
FROM MyTable
ORDER BY MyTable.SomeFieldIndexed
OFFSET @SizePerPage * (@Page - 1) ROWS
FETCH NEXT @SizePerPage ROWS ONLY;
END
GO
-- How to use
-- EXEC MyTablePagerSP 1, 10
-- Output: First 10 rows. Order based on ordered column (MyTable.SomeFieldIndexed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment