How to apply paging in SQL Query ?

Easy way apply paging in SQL Query 

Steps by Step 

  1.  Pass the page number and how many records per page you would like to fetch 
  2. Remember to  have ORDER BY column name in your query


DECLARE @PageNumber AS INT, 
@RowsperPage AS INT
SET @PageNumber = 1
SET @RowsperPage = 10
SELECT * 
FROM cu_customer 
ORDER BY CustomerID
OFFSET ((@PageNumber – 1) * @RowsperPage) ROWS
FETCH NEXT @RowsperPage ROWS ONLY OPTION (RECOMPILE);

Published by arjunpremier

Software Engineer, Blogger,

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started