WebsiteSpark

Sunday 1 April 2012

Pagination in SQL Server 2012

Pagination in SQL Server 2012 is implemented using “OFFSET X ROWS”, followed by “FETCH NEXT Y ROWS ONLY” . you can replace X and Y with integer variables as code given below.

DECLARE @offset INT;
DECLARE @rows INT;


 SET @offset = 300;
 SET @rows = 15;

SELECT
*
FROM Person.Person
ORDER BY BusinessEntityID
OFFSET @offset ROWS
FETCH NEXT @rows ROWS ONLY


The above example will fetch next 15 rows represented by @rows, starting from offset 300 represented by @offset of BusinessEntityId.


Enjoy!

No comments:

Post a Comment