Goal is trivial: get total row count and some data page.
When I use OFFSET...FETCH approach to implement paging with total row counting I running into following issue: when we pass some big page number (e.g. we have only 100 rows, but requested 15th with 10 records per page) COUNT(*) OVER() statement has never called, because result set is empty. So, we can not get right total row count in this case.
Is there way to get right total row count using OFFSET ... FETCH approach even when big page number passed?
FYI, OFFSET ... FETCH approach is that:
SELECT
...
Total = COUNT(*) OVER()
FROM Table1
ORDER BY Col1
OFFSET (@PageNum-1) * @PageSize ROWS
FETCH NEXT @PageSize ROWS ONLY;