SQL 2005 Query Reference

I have a table with 50 records (users with data like Name Surname Location, etc.)

I want to create a query that will give me users from line 1 to line 10. Then another query that gives me users from 11 to 20, etc.

Is there a way how to do this?

thank

0


source to share


2 answers


http://www.singingeels.com/Articles/Pagination_In_SQL_Server_2005.aspx



+5


source


For those who don't feel like clicking: The solution is to add the row numbers to the result set (using syntax "ROW_NUMBER() OVER (...)"

) and then refer to the row number column in the WHERE clause. How:

SELECT 
    *,
    ROW_NUMBER() OVER (ORDER BY LastName, FirstName) AS RowNumber
  FROM
    Table
  WHERE
    RowNumber > 10 
    AND RowNumber <= 20

      



10 and 20 can be parameters for recording start and stop.

+1


source







All Articles