I have the query below that is selected data in a ‘framed’ manner. There is a lot of data and I only want to get one ‘page’ at a time.
SELECT
entryDateTime,
value
FROM
(
SELECT
ROW_NUMBER() OVER(ORDER BY entryDateTime DESC) AS rowNum,
entryDateTime,
value
FROM
table
WHERE
entryDateTime BETWEEN @start AND @end
) AS TempTbl
WHERE
rowNum BETWEEN @startRow AND @endRow;
I want to know if it’s possible to get the maximum rowNum value from this. Basically, I am looking to get a count of all possible rows so I know how many pages of data exist for the given time span (I expect the maximum rowNum to be bigger than @endRow). Does anyone know how to do this?
Typically you would execute 2 separate queries, one that just does a COUNT(*), and then a separate one that gets the current page of data.