Reputation: 6747
I have table with 50 entries (users with such details like Name Surname Location etc)
I want to create a query that give me users from row 1 to row 10. Then another query that give me users from 11 to 20 and so on.
Is there any way how to do that?
Thanks
Upvotes: 0
Views: 123
Reputation: 9457
For those who don't feel like clicking through: the solution is to add row numbers to the resultset (using the "ROW_NUMBER() OVER (...)"
syntax) and then refer to that row number column in a WHERE clause. Like:
SELECT
*,
ROW_NUMBER() OVER (ORDER BY LastName, FirstName) AS RowNumber
FROM
Table
WHERE
RowNumber > 10
AND RowNumber <= 20
The 10 and 20 can then be parameters for the start and stop record.
Upvotes: 1
Reputation: 143194
http://www.singingeels.com/Articles/Pagination_In_SQL_Server_2005.aspx
Upvotes: 5