ice78991
Programmer
- Nov 20, 2006
- 216
I am using the following stored procedure to page through query results
CREATE PROCEDURE dbo.ShowLog
@PageIndex INT,
@PageSize INT
AS
BEGIN
WITH LogEntries AS (
SELECT ROW_NUMBER() OVER (ORDER BY Date DESC)
AS Row, Date, Description
FROM LOG)
SELECT Date, Description
FROM LogEntries
WHERE Row between
(@PageIndex - 1) * @PageSize + 1 and @PageIndex*@PageSize
END
My question is, what is the most efficient way to get the total number of records returned by the query so that I can include a caption which says
Results 1 to 10 of a total of 200 (for example)
CREATE PROCEDURE dbo.ShowLog
@PageIndex INT,
@PageSize INT
AS
BEGIN
WITH LogEntries AS (
SELECT ROW_NUMBER() OVER (ORDER BY Date DESC)
AS Row, Date, Description
FROM LOG)
SELECT Date, Description
FROM LogEntries
WHERE Row between
(@PageIndex - 1) * @PageSize + 1 and @PageIndex*@PageSize
END
My question is, what is the most efficient way to get the total number of records returned by the query so that I can include a caption which says
Results 1 to 10 of a total of 200 (for example)