Serial Number for records with Row_number() function in Sql Server

Serial Number for generated records in sqlserver can be achieved by using ROW_NUMBER function.
 
Example :
 
SELECT
     ROW_NUMBER() OVER (ORDER BY EmpId) AS Sno,
     EmpId, EmpName, Dept, Zip, Country
FROM Employee
 
Output :
 
Sno      EmpId              EmpName                Dept      Zip          Country
1        NIT2727          Ujjwala Datta               IT      522002        India
2        NFI9999          Pavan Kumar                Fin     522002        India
 

Advertisements

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