Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web application using SQL Server 7.0 that returns the results of a query page. Since a query could return thousands of rows I only display 50 at a time for speed. The user then hits the next arrow to display rows 51 - 100. I would like to be able to do all of this in a stored procedure but I have not figured out how to do so using Sql. I know about the Top 50 but that doesn't help me with the next 50 or the next 50 after that. I have stumped several DBAs with maybe Here can help?
Posted

1 solution

There are a couple of ways.
Try this:
SQL
WITH myTableWithRows AS (
    SELECT (ROW_NUMBER() OVER (ORDER BY myTable.SomeField)) as row,*
    FROM myTable)
SELECT * FROM myTableWithRows WHERE row = BETWEEN 50 AND 99
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900