Row Number in SQL Server 2005

In SQL Server 2005, you can use built in ROW_NUMBER() or RANK() function to generate row number for selected record set.

Syntax:

ROW_NUMBER () OVER (ORDER BY column name)

RANK() OVER (ORDER BY column name)

Example:

ROW_NUMBER ():

SELECT ROW_NUMBER()
OVER (ORDER BY applicantInformation_Name DESC) AS SerialNo,
applicantInformation_Name,
applicantInformation_Email,
applicantInformation_Phone_No
FROM t_ApplicantInformation

RANK():

SELECT RANK()
OVER (ORDER BY applicantInformation_Name DESC) AS SerialNo,
applicantInformation_Name,
applicantInformation_Email,
applicantInformation_Phone_No
FROM t_ApplicantInformation

Output:

Those two quires produce the same result.

Thanks
A Rahim Khan

Advertisements
  1. March 28th, 2010

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: