Saturday, 2 November 2013

how to select nth row in sql server without using row_number() and without using order by?

how to select nth row in sql server without using row_number() and without using order by??
Also without using cursors.(cursor can be one of the solution, but it decreases the performance when there are lacs of records.)

 

 

Solution:

 

declare @NewId bigint,@NewFname varchar(20),@NewLname varchar(20),@NewSalary money   select top 5 @NewId =eid,@NewFname = fname @NewLname=lname,@NewSalary=salary from Tbl_Emp_Detail   select @NewId ,@NewFname,@NewLname,@NewSalary

 

OR

declare @NewId bigint   select top 5 @NewId=eid from Tbl_Emp_Deatail   select * from Tbl_Emp_Detail where eid=@NewId

 

 

Here replace top 5 by top 'n' 

view my answer in codeproject.com

thank you :)