I’m trying to create a stored proc that indicates a pay raise for two types of employees. Those with above average salaries and those with lower than average salaries. Both fnHeadCount and fnAverageSalary are functions that I’ve created that are working and have worked in the past. I’m getting an error with the second part. It says incorrect syntax for the equal sign and the 1.4075.
Here is the code. I made the errors bold:
CREATE PROC RAISEA9
BEGIN
UPDATE tblEmployeeA9
SET AnnualSalary=ROUND(1.025*AnnualSalary,2)
SELECT dbo.fnHeadCount(JobTitle)
FROM dbo.tblEmployeeA9
WHERE Active='Y'
HAVING (dbo.fnHeadCount(JobTitle)-1 >=2) AND (AnnualSalary > dbo.fnAverageSalary(JobTitle))
END
BEGIN
SET AnnualSalary=ROUND(1.0475*AnnualSalary,2)
SELECT dbo.fnHeadCount(JobTitle)
FROM dbo.tblEmployeeA9
WHERE Active='Y'
HAVING (dbo.fnHeadCount(JobTitle)-1 >=2) AND (AnnualSalary <= dbo.fnAverageSalary(JobTitle))
END
UPDATE:
Additionally, while we are on the same page, as you strive to close the gap between the rich and not so rich, note that first update will raise average salary for second update. Only ordering of operations (AnnualSalary >, AnnualSalary <=) saves you from giving someone two raises.
The two updates are essentially the same and could be rewritten easily:
Of course, AND (AnnualSalary <= dbo.fnAverageSalary(JobTitle)) and AND (AnnualSalary <= dbo.fnAverageSalary(JobTitle)) would be deleted.