Link to home
Start Free TrialLog in
Avatar of enrique_aeo
enrique_aeo

asked on

sql server 2012 - OFFSET and FETCH clauses

Hi experts, can you gime an store procedure with

We recommend using OFFSET and FETCH clauses instead of the TOP clause to implement a paging solution query and limit the number of rows sent to a client application
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of enrique_aeo
enrique_aeo

ASKER

CREATE PROCEDURE procGetPagedData(@pageno int, @pagesize int)
      AS
BEGIN
      DECLARE @offset INT
      SET @offset = @pageno * @pagesize

      SELECT orderid, custid, empid, orderdate
      FROM Sales.Orders
      ORDER BY orderdate, orderid DESC
      OFFSET @offset ROWS FETCH NEXT @pagesize ROWS ONLY;
END