0

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?

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • 2
    The issue is the missing schema. As the error message implies without a schema it looks for a **built-in** function – Martin Smith Oct 25 '22 at 12:30
  • Related reading: [Should you choose the MONEY or DECIMAL(x,y) datatypes in SQL Server?](https://stackoverflow.com/questions/582797/should-you-choose-the-money-or-decimalx-y-datatypes-in-sql-server) – Thom A Oct 25 '22 at 12:35
  • Not to mention, as well, that an **inline** table value function would likely be more performant. – Thom A Oct 25 '22 at 12:40

0 Answers0