Always return X rows with variable starting row
Okay, so we need to find out how many rows are in the table, and how many rows are left once we've moved to the marker defined by @Partial.

-- simple variable to hold the offset:
DECLARE @offset int;

;WITH x(o,c) AS 
(
  SELECT 
    -- how many rows are at or past the @Partial marker?
    SUM(CASE WHEN CustomerID &gt;= @Partial THEN 1 END),
    -- how many rows total?
    COUNT(*) 
  FROM @Customers
 ) 
 -- the magic: a conditional that determines if we're 
 -- too close to the end, and subtracts the difference
 -- between how close we are and how close we want to be
 SELECT @offset = (c-o) - CASE 
   WHEN @NumWindowRows &gt; (c - (c-o)) THEN
       (@NumWindowRows - (c - (c-o))) 
   ELSE 0 END
FROM x;

SELECT 
  ROW_NUMBER() OVER (ORDER BY CustomerID),
  CustomerID, 
  Name
FROM @Customers
ORDER BY CustomerID
OFFSET @offset ROWS
FETCH NEXT @NumWindowRows ROWS ONLY;


You could probably do this all inline instead of using the @offset variable, but it gets messy very fast, and I don't think it's possible to avoid the additional scan required to derive those counts anyway.

This is far simpler than your logic. But it assumes that you will always order by CustomerID and never add additional filters. If there are less than @NumWindowRows rows in the table, well...