Dear Drew, I'm sorry, it was not my intention 🙂
I know that's difficult to explain and i'm trying to do my best
Ok, here some data to seed the database
CREATE TABLE Tab1 (Col1 int,Col2 nvarchar(5),Col3 nvarchar(10))
CREATE TABLE Tab2 (Col1 nvarchar(10),Col2 int)
CREATE TABLE Tab3 (Col1 int,Col2 nvarchar(10))
declare @id int = 1
while @id >=1 and @id <= 32
begin
insert into Tab1 values(@id, 'photo', 'movie')
select @id = @id + 1
end
set @id = 1
while @id >=1 and @id <= 75
begin
insert into Tab2 values('movie', @id)
select @id = @id + 1
end
set @id = 1
while @id >=1 and @id <= 24
begin
insert into Tab3 values(@id, 'movie')
select @id = @id + 1
end
if we try to run the first query with @Skip = 31, @Take = 10 and @SearchTerm = N'movie' the output will be:
TABLE WITH 32 ROWS => OFFSET 31(wrong) ROWS FETCH NEXT 10(wrong) ROWS ONLY
TABLE WITH 75 ROWS => OFFSET 31(wrong) ROWS FETCH NEXT 10(wrong) ROWS ONLY
TABLE WITH 24 ROWS => OFFSET 31(wrong) ROWS FETCH NEXT 10(wrong) ROWS ONLY
TOTAL COUNT => 131
but that's wrong! The correct output must be:
TABLE WITH 32 ROWS => OFFSET 31 ROWS FETCH NEXT 1 ROWS ONLY
TABLE WITH 75 ROWS => OFFSET 1 ROWS FETCH NEXT 9 ROWS ONLY
TOTAL COUNT => 131
Or with @Skip = 70, @Take = 15 and @SearchTerm = N'movie' an correct output must be:
TABLE WITH 75 ROWS => OFFSET 38 ROWS FETCH NEXT 15 ROWS ONLY
TOTAL COUNT => 131
Hope that can help, again thank you all very much