I've seen a lot of examples but none of them seem to help me enough.
Here are the ones I've implemented and working, but very slow:
Approach 1:
SELECT *
FROM
LogVisits T (NOLOCK)
WHERE
T.Msisdn = @TempMsisdn
ORDER BY
T.[VisitUrlCreatedDate], T.[VisitId] DESC
OFFSET @RecordStartIndex ROWS
FETCH NEXT (@RecordEndIndex - @RecordStartIndex) ROWS ONLY;
Approach 2:
SELECT
*
, (SELECT COUNT(*) FROM vLogVisit) AS [TotalRecordCount]
FROM
(
SELECT
ROW_NUMBER() OVER(ORDER BY T.[VisitUrlCreatedDate] DESC, T.[VisitId] DESC) AS IndexRank --, T.VisitUrlId DESC
, T.*
FROM
vLogVisit T
WHERE
T.Msisdn = @TempMsisdn
) AS VisitLogs
WHERE
IndexRank BETWEEN @RecordStartIndex AND @RecordEndIndex
ORDER BY
VisitUrlCreatedDate DESC
, VisitId DESC
I think these both approaches take all first and then get the portion I want.
Since the count of the data before taking the portion is more than 100k, is there a faster way?