I have the following query where I am trying to employee id from payroll records where the employee that worked over time excluding sick, vacation, holiday and Jury time. This query is returning a few records where the hours is equal to 40.
SELECT E.EMPLOYEE_ID FROM Payroll.PAYROLLRECORDS PR
INNER JOIN Payroll.EMPLOYEE E ON E.ID = PR.EMPLOYEEID
WHERE E.PAYROLL_TYPE IN ('W')
AND PR.PAYROLLPOSTID = 14
GROUP BY E.EMPLOYEE_ID
HAVING (SUM(ISNULL(PR.REGULAR_HOURS,0)) - SUM(ISNULL(PR.SICK_HOURS,0)) - SUM(ISNULL(PR.VACATION_HOURS,0)) - SUM(ISNULL(PR.HOLIDAY_HOURS,0)) - SUM(ISNULL(PR.RT_HOURS,0))) > 40
ORDER BY E.EMPLOYEE_ID