correlation name not found on SQL Anywhere

╄→尐↘猪︶ㄣ 提交于 2019-12-02 09:08:53

You have given the table an alias, so you need to use it. I would recommend using aliases for all the tables:

DECLARE @totalAmountOfMoney int;

SELECT @totalAmountOfMoney = s.AmountInEuros * DATEDIFF(month, e.StartDat, '2019-01-16') 
FROM dba.Employees e INNER JOIN
     dba.Salarygroup s
     ON e.SalaryId = s.SalaryId
WHERE e.personalID = @PersonalID;

Note that the g alias is not defined in your query. StartDat comes from Employees, so I changed that to e. I am guessing that AmountInEuros comes from s.

Maybe you forgotten to refer the second table using the Alias 's' you created:

ALTER FUNCTION "dba"."countTotalAmountOfMoney"(@PersonalID int)
   RETURNS int
   AS
   BEGIN
   DECLARE @totalAmountOfMoney int;
   SELECT  @totalAmountOfMoney = g.AmountInEuros * DATEDIFF(month, g.StartDat, 
        '2019-01-16') 
   FROM dba.Employees 
   Inner Join dba.Salarygroup s
   ON   dba.Employees.SalaryId = s.SalaryId

   RETURN @totalAmountOfMoney;
END
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!