i want to use Pagination And Total Number Of Rows From One SELECT statement in SQL Server

1 Answers

  1. Aditya Kumar Patel
    Pagination And Total Number Of Rows From One SELECT
    9/8/2018 4:58:06 PM

     here I am going to give you a simple example, how to write SQL Query using pagination and Get total row number in a single select statement in SQL Server.

     

    DECLARE @PageNumber AS INT, @RowspPage AS INT
    SET @PageNumber =2
    SET @RowspPage = 5
    SELECT * FROM (
        SELECT RowsCount=COUNT(*)over(),ROW_NUMBER() OVER(ORDER BY ID) AS Num,
                        * FROM Customer )AS TBL
    WHERE Num BETWEEN ((@PageNumber - 1) * @RowspPage + 1) AND (@PageNumber * @RowspPage)
    ORDER BY TBL.ID

    I hope it will help to you.


Leave a answer

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like