how to find nth highest salary

Answer Posted / vidit

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 ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are cascading parameters in ssrs reports?

176


What is perspective, have you ever created perspective? : sql server analysis services, ssas

498


What command do we use to rename a database?

618


Is null in sql server?

544


How can you list all the table constraints in a database?

514






What can be used instead of trigger?

628


what is bit datatype? : Sql server database administration

508


what is bit datatype and what's the information that can be stored inside a bit column? : Sql server database administration

539


What is the maximum length of an alert name?

606


What are click through reports?

99


How to make conditional sum in ssrs?

132


How do I create a stored procedure in sql server?

521


How sql server enhances scalability of the database system?

592


What are triggers? How many triggers you can have on a table? How to invoke a trigger on demand?

751


Suppose you want to implement the one-to-one relationships while designing tables. How would you do it?

547