how to find nth highest salary

Answer Posted / sanchit dubey

DECLARE @SQL VARCHAR(2000), @N INT
SET @N = 5
SET @N = @N - 1

SET @sql = 'select top 1 salary from ABC where salary not
in ( SELECT TOP ' + CAST(@n AS VARCHAR(100)) + ' salary
FROM ABC order by salary desc ) ' + ' order by salary desc '

SELECT @SQL
EXEC @SQL

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to generate create table script on an existing table in ms sql server?

743


How to create and drop temp table in sql server?

666


Can we use where clause in union?

691


Is sql server free?

599


what is a deadlock? : Sql server database administration

582






What is difference between inner join and full join?

662


What is a primary key?

615


how to create “alternate row colour”?

115


What is wide table?

620


Explain iaas, paas and saas?

80


Do you know what is difference between stored procedure and user defined function?

700


What is the meaning of lock escalation and why/how to stop this? : sql server database administration

699


What is spatial and temporal data?

620


What is DCL?

676


Tell me in brief how sql server enhances scalability of the database system?

613