Last active
October 15, 2018 16:30
-
-
Save dionnyprensa/4212a924455368a4055c121b0f7fab96 to your computer and use it in GitHub Desktop.
Simple pager for sql server
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
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