Showing posts with label SQL Paging Query. Show all posts
Showing posts with label SQL Paging Query. Show all posts

Sunday, January 17, 2016

SQL - Paging In SQL Query

DECLARE @PageNumber INT = 1, --@PageNumber comming from gridview from codebihind
        @PageSize   INT = 100  --@PageSize comming from gridview from codebihind

SET NOCOUNT ON;

SELECT *
FROM dbo.<TableName>
WHERE <Condition> = <value>
ORDER BY <Column_Name>
OFFSET @PageSize * (@PageNumber - 1) ROWS
FETCH NEXT @PageSize ROWS ONLY OPTION (RECOMPILE);