how to find nth highest salary

Answer Posted / mayur

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 ) '

SELECT @SQL

EXEC (@SQL)

Is This Answer Correct ?    24 Yes 71 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain difference between cross join and full outer join?

754


Can a stored procedure call itself or a recursive stored procedure? How many levels of sp nesting is possible?

816


What is a transactions?

789


How can I add Reporting Services reports to my application?

105


Explain four layers of abstraction microsoft architectured?

138


What is the difference between a local and a global temporary table?

842


What are the properties and different types of sub-queries?

782


How to transfer data from a cursor to variables with a "fetch" statement?

780


What is a fill factor?

837


What is a primary key?

707


How to restore performance issues and how to check?

1729


Why normalization is used?

746


We need to perform what steps in the following order to work with a cursor?

923


what's the difference between delete table and truncate table commands? : Sql server database administration

684


What is auditing in sql server?

700