CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS BEGIN RETURN ( SELECT Max(Salary) from Employee where Salary not in (Select DISTINCT TOP (@N-1) Salary from Employee order by Salary Desc) ); END