我有一个SQL查询,我在那里提取员工时间卡信息。它提取姓名,工资单ID,Locaiton,正常工作时间和加班时间。但是,我无法弄清楚如何使用case和Sum正确地舍入常规和加班时间。下面是我的代码,不是四舍五入。
SELECT Employee_Tb.First_Name + ' ' + Employee_Tb.Last_Name AS Name, Employee_Tb.Home_Store_Id, Employee_Tb.Payroll_Id,
CASE WHEN SUM(Payroll_Hours_Tb.Hours_Worked) > 40.0 THEN 40.0 ELSE Round(SUM(Payroll_Hours_Tb.Hours_Worked), 2) END AS RegHours,
CASE WHEN SUM(Payroll_Hours_Tb.Hours_Worked) > 40.0 THEN Round(SUM(Payroll_Hours_Tb.Hours_Worked), 2) - 40.0 ELSE 0.0 END AS OTHours
FROM Employee_Tb INNER JOIN
Payroll_Hours_Tb ON Employee_Tb.Employee_Id = Payroll_Hours_Tb.Employee_Id
WHERE (Payroll_Hours_Tb.Work_Date BETWEEN @startdate AND @enddate)
GROUP BY Employee_Tb.Payroll_Id, Employee_Tb.First_Name, Employee_Tb.Last_Name, Employee_Tb.Home_Store_Id
ORDER BY Employee_Tb.Home_Store_Id
结果的一个例子是:正常时间“21.91999999”
它应该是:“21.92”
答案 0 :(得分:0)
尝试使用
convert(int,Round(SUM(Payroll_Hours_Tb.Hours_Worked), 0))
这将消除额外的整数