Did you want to add a row number column in a select result!? Did you think it is hard to do that!? Luckly, SQL Server 2005 has added a row number function that can help you paging records for your database application.
Let’s me show an example for you to learn more about it.
Example:
This shows the first 10 records in employee table which is order by the entry date
SELECT Name, EntryFROM (select row_number() over (order by EntryDate Asc) AS RowNo, Name, EntryDate FROM Employee) AS Employee WHERE RowNo between 1 and 10
This shows the next 10 records in employee table which is order by the entry dateSELECT Name, EntryFROM (select row_number() over (order by EntryDate Asc) AS RowNo, Name, EntryDate FROM Employee) AS Employee WHERE RowNo between 11 and 20