Row Number Function In SQL Server Server 2005

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

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.