Offset Fetch Next to get all rows
问题 I have a query in SQL Server 2012 that should get back a number of records based on the page size I specify and the page it is on. It looks like this: SELECT LocID, LocName FROM Locations ORDER BY LocName OFFSET @PageNum ROWS FETCH NEXT @PageSize ROWS ONLY The code is pretty simple. What I need to do, though, is put that into a function to return the paging correctly. However, I could also be needing all records back from this function, so I need to have the option of calling the function