Below I created a very simple function that sums all the employees' salaries from a specific department provided as the parameter.
CREATE FUNCTION sumAllSalaries(@dptName VARCHAR(30))
RETURNS MONEY
BEGIN
RETURN (
SELECT SUM(e.salary)
FROM Employee as e
INNER JOIN Departament as d
ON e.idDepartament = d.idDepartament
WHERE d.departamentName = @dptName
)
END
Yet when I try to print the result, such as
PRINT sumAllSalaries('Research')
SQL Server returns me the message
sumAllSalaries is not a recognized built-in function name
Can anyone explain to me why is this message showing up?