Stored procedure for Paging.

Asp.net using C#

Posted by iks on 1/16/2015 10:21:36 AM

The following Stored Procedure works great for Paging:

 

--Third page with five rows

CREATE PROCEDURE paging
AS
DECLARE
@PageNumber INT,
@RowspPage AS INT
SET @PageNumber = 3
SET @RowspPage = 5
SELECT * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY Blog) AS NUMBER,
Blog, postTitle, postSubTitle, content, createdAt, username FROM Blog
) AS TBL
WHERE NUMBER BETWEEN ((@PageNumber - 1) * @RowspPage + 1) AND (@PageNumber * @RowspPage)
ORDER BY id
return


Comments

Please leave your comment here!