Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come possiamo eseguire l'impaginazione nel recuperare il valore con 100 record ciascuno in sql

Usa CTE e OFFSET :

@RecordIndex=Start Row No
@PageSize=No of Rows to fetch

;WITH CTE_Results
AS (
SELECT 
    ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS ROWNUM,
    Count(*) over () AS TotalCount,
    *
    FROM TableName  
)      
Select * from CTE_Results 
ORDER BY ROWNUM
OFFSET (@RecordIndex) ROWS
FETCH NEXT @PageSize ROWS ONLY;