Is there any way in SQL Server to get the results starting at a given offset? For example, in another type of SQL database, it\'s possible to do:
SELECT * FR
I've been searching for this answer for a while now (for generic queries) and found out another way of doing it on SQL Server 2000+ using ROWCOUNT and cursors and without TOP or any temporary table.
Using the SET ROWCOUNT [OFFSET+LIMIT]
you can limit the results, and with cursors, go directly to the row you wish, then loop 'till the end.
So your query would be like this:
SET ROWCOUNT 75 -- (50 + 25)
DECLARE MyCursor SCROLL CURSOR FOR SELECT * FROM pessoas
OPEN MyCursor
FETCH ABSOLUTE 50 FROM MyCursor -- OFFSET
WHILE @@FETCH_STATUS = 0 BEGIN
FETCH next FROM MyCursor
END
CLOSE MyCursor
DEALLOCATE MyCursor
SET ROWCOUNT 0