Thursday, 28 January 2016

How to Select Records from sql as Page of given size ?





DECLARE @PageNum AS INT;
DECLARE @PageSize AS INT;
SET @PageNum = 2;
SET @PageSize = 10;

WITH UserRN AS
(
    SELECT ROW_NUMBER() OVER(ORDER BY [fldSno], fldUserType) AS RowNum
          ,fldUserID,
                fldUserType,
                 fldName
         
      FROM [CRP].[tblUserReg]
)

SELECT *
  FROM UserRN
 WHERE RowNum BETWEEN (@PageNum - 1) * @PageSize + 1
                  AND @PageNum * @PageSize
 ORDER BY RowNum, fldUserType



Result as shown below:-


No comments:

Post a Comment