Return total records from SQL Server when using ROW_NUMBER
问题 I would like to return the total number of records in the database so I can set up pagination. How do I return the total number of records in the DB when using the following paging method in SQL Server 2008? ALTER PROCEDURE [dbo].[Nop_LoadAllOptimized] ( @PageSize int = 20, @PageNumber int = 1, @WarehouseCombinationID int = 1, @CategoryId int = 58, @OrderBy int = 0, @TotalRecords int = null OUTPUT ) AS BEGIN WITH Paging AS ( SELECT rn = (ROW_NUMBER() OVER ( ORDER BY CASE WHEN @OrderBy = 0 AND