CREATE FUNCTION Salary.SecondHighestSalary()
Returns int
AS
BEGIN
Declare @salary int;
SELECT TOP 1 salary FROM (
SELECT TOP 2 salary FROM Salary
ORDER BY salary DESC
) as maxsalary ORDER BY salary ASC
Return @salary
END
Hello everyone, I am trying to create a sql function of getting the second highest salary by using the above syntax but i am getting the error:
"Select statements included within a function cannot return data to a client."
Can anyone please tell me what is the actual syntax to write the function or just turn my code back with the correct syntax. Thanks in advance.