Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paging With SQL Server 2005

Status
Not open for further replies.

ice78991

Programmer
Joined
Nov 20, 2006
Messages
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)



 
You can return a @@ROWCOUNT of the query in an output variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top