Last active
January 30, 2017 09:28
-
-
Save AndiSHFR/eae134af7e58696c77de011686ba3ffc to your computer and use it in GitHub Desktop.
Paging Example in Sql Server (like mysql LIMIT+OFFSET)
This file contains 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
-- Pageing in SQL Server like mysql (LIMIT + OFFSET) | |
DECLARE @Offset INT = 3 | |
DECLARE @Limit INT = 10 | |
;WITH Results_CTE AS | |
( | |
SELECT | |
COUNT(*) OVER () as TotalRows, | |
ROW_NUMBER() OVER (ORDER BY name) AS RowNum, | |
id, name, crdate, refdate | |
FROM master..sysobjects | |
WHERE xtype = 'S' | |
) | |
SELECT * | |
FROM Results_CTE | |
WHERE RowNum >= @Offset | |
AND RowNum < @Offset + @Limit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment