Using OFFSET-FETCH, how to default number of rows to "all rows"?
<p>Envision a stored procedure which takes <code>@skip</code> (offset) and <code>@take</code> (maximum number of rows to return. If <code>@take</code> is <code>null</code>, then I want to return "all rows after applying the offset".</p>

<p>I can accomplish this by counting the number of rows in the table/view if <code>@take</code> is <code>null</code>, but then I have to perform two queries which is, of course, not optimal. I was hoping there was an option similar to <code>FETCH [NEXT] ALL ROWS</code>.</p>

<pre><code>DECLARE @skip BIGINT = 0;
DECLARE @take BIGINT = NULL;

IF (@take IS NULL) SET @take = (SELECT COUNT(*) FROM SomeTable);

SELECT *
FROM SomeTable
ORDER BY SortOrder
OFFSET @skip ROWS
FETCH NEXT @take ROWS ONLY
</code></pre>