Can anyone please let me know where of the SQL query is wrong?
The error is
Incorrect syntax near "return"
Code:
CREATE FUNCTION getNthHighestSalary(@N INT)
RETURNS INT
AS
BEGIN
WITH ranksalary AS
(
SELECT
salary,
ROW_NUMBER() OVER (ORDER BY Salary DESC) AS Rank
FROM
Employee
)
RETURN (SELECT Salary AS getNthHighestSalary
FROM ranksalary
WHERE Rank = @N);
END
SELECTinto a local variable in your function, and then return that variable's value.