Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Como podemos fazer paginação na busca do valor com 100 registros cada em sql


Usar 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;