MS SQL Solution Row_Number and Max for NULL
Using Row_Number to create the rank. Rank and Dense_Rank also work as well.  Using Max to return NULL if there is no # highest salary.\n\nThis also works with #
Using Row_Number to create the rank. Rank and Dense_Rank also work as well.  Using Max to return NULL if there is no # highest salary.\n\nThis also works with #176 "Second Highest Salary".\n\nCREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS\nBEGIN\n    RETURN (\n\nSELECT salary = MAX(salary) FROM (\n    SELECT  ROW_NUMBER() OVER(ORDER BY salary DESC) AS ranking, salary FROM\n    (\n        SELECT DISTINCT Salary FROM Employee) A\n    ) B\nWHERE ranking =  @N\n        \n    );\nEND
['MS SQL Server']