Here I am trying to display Row number without using predefined function (ROW_NUMBER()) available in SQLServer
Consider Table Emp having following columns
Empname varchar(50)
EmpId int PK
Here I am assuming Empid as PK but not an
identity column.
SQL QUERY
I have used inner query to display row number.
Select Empname, EmpId,
(Select Count(*) from Emp emp1 where emp1.EmpId< emp2.EmpId ) AS Rownumber from
Emp emp2
where Empname is not null
order by Empname
I also face this question in many interviews as well.

Karthikeyan TPosted Apr 7, 2015, 2:15 AM
Thanks for the post
Ramesh RPosted Nov 27, 2013, 10:15 AM
Is it work if EmpID is not in asc or dsc order?