我需要获取记录的总数以及分页。目前我在 SQL Server 2012 中按照下面列出的方式进行操作。这需要一个单独的查询来获取计数。SQL Server 2012 中是否有任何改进的方法?
ALTER PROCEDURE dbo.tpGetPageRecords
(
@OffSetRowNo INT,
@FetchRowNo INT,
@TotalCount INT OUT
)
AS
SELECT CSTNO, CSTABBR
FROM DBATABC
WHERE CSTABBR LIKE 'A%'
ORDER BY CSTNO
OFFSET ( @OffSetRowNo-1 ) * @FetchRowNo ROWS
FETCH NEXT @FetchRowNo ROWS ONLY
SET @TotalCount =
(SELECT COUNT(*)
FROM DBATABC
WHERE CSTABBR LIKE 'A%')
GO