需要帮助舍入结果

时间:2017-09-06 23:57:29

标签: sql-server

我有以下报告,

{'Date': 'Wed, 06 Sep 2017 23:45:52 GMT', 'Server': 'Apache', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Pragma': 'no-cache', 'X-Frame-Options': 'SAMEORIGIN', 'X-Cache-Page': 'MISS', 'Set-Cookie': 'locale=en_GB; Expires=Mon, 05-Mar-2018 23:45:52 GMT; Domain=.napoleongames.be; Path=/, user=false; expires=Mon, 05-Mar-2018 23:45:52 GMT; Max-Age=15552000; path=/; domain=.napoleongames.be, loyalty=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=.napoleongames.be', 'Strict-Transport-Security': 'max-age=15768000', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'Content-Length': '10840', 'Connection': 'close', 'Content-Type': 'text/html'}

这将返回所选日期范围内每个人每天的工作时间,并且工作正常:

    select E.FullName, EL.DateTimeStart, EL.DateTimeStop, E.EmployeeStatusCode, EL.ExtraMinutes,
       Sum(El.ShiftTime /60.0 + (ExtraMinutes / 60.0)) as TotalHoursWorked
FROM       dbo.Employee AS E
INNER JOIN dbo.employeelog AS EL 
ON         E.EmployeeKey = EL.EmployeeKey   
where      EL.DateTimeStart BETWEEN (@StartDate) AND (@EndDate +1)and EmployeeStatusCode = @EmployeeStatusCode
GROUP BY   FullName, EL.DateTimeStart, EL.DateTimeStop, E.EmployeeStatusCode, EL.ExtraMinutes
having     Sum(El.ShiftTime /60.0 + (ExtraMinutes / 60.0)) > 0
ORDER BY   FullName

我现在才发现问题,因为我正试图围绕结果。

我尝试使用 2017-04-15 13:53:02.040 2017-04-15 14:03:41.177 C 0 0.166666 2017-04-15 14:03:41.177 2017-04-15 14:12:00.303 C 0 0.150000 2017-04-15 14:16:29.610 2017-04-15 22:22:47.953 C -30 7.600000 2017-06-08 06:30:00.000 2017-06-08 12:08:54.210 C -30 5.133333 2017-06-08 12:08:54.210 2017-06-08 12:15:53.850 C 0 0.116666 2017-06-08 12:15:53.850 2017-06-08 14:37:10.040 C 0 2.366666 ,但问题在于每个员工的每日时间都在四舍五入。

Round()/0.5, 0) *0.5

我们系统目前的设置方式是员工的工作时间在一周结束时2017-04-15 13:53:02.040 2017-04-15 14:03:41.177 C 0 0.000000 2017-04-15 14:03:41.177 2017-04-15 14:12:00.303 C 0 0.000000 2017-04-15 14:16:29.610 2017-04-15 22:22:47.953 C -30 7.500000 2017-06-08 06:30:00.000 2017-06-08 12:08:54.210 C -30 5.000000 2017-06-08 12:08:54.210 2017-06-08 12:15:53.850 C 0 0.000000 2017-06-08 12:15:53.850 2017-06-08 14:37:10.040 C 0 2.500000 ,而不是在每天结束后,所以我只需要计算总和,或者每周的总工时。抱歉,如果它令人困惑,我很困惑自己,我需要一些帮助。 :P

我在ms SQL server management studio中编写我的报告,并在报告生成器中完成它们。 非常感谢尼克

2 个答案:

答案 0 :(得分:0)

很抱歉将此评论添加到答案部分,但显然我的观点不够高,视线允许我发表评论: - )

这是我的评论/问题,看起来您列出了每个员工和每天的时间。您是否希望添加“周累计”行?或者您是否想要计算每周的舍入金额并将其应用于每一天(这种方式听起来很复杂)?请解释一下。

答案 1 :(得分:0)

你是否在TotalHoursWorked周围?还是我误会了?舍入到最接近的数千。

select E.FullName, EL.DateTimeStart, EL.DateTimeStop, E.EmployeeStatusCode, EL.ExtraMinutes,
       round(Sum(El.ShiftTime /60.0 + (ExtraMinutes / 60.0)),3) as TotalHoursWorked
FROM       dbo.Employee AS E
INNER JOIN dbo.employeelog AS EL 
ON         E.EmployeeKey = EL.EmployeeKey   
where      EL.DateTimeStart BETWEEN (@StartDate) AND (@EndDate +1)and EmployeeStatusCode = @EmployeeStatusCode
GROUP BY   FullName, EL.DateTimeStart, EL.DateTimeStop, E.EmployeeStatusCode, EL.ExtraMinutes
having     Sum(El.ShiftTime /60.0 + (ExtraMinutes / 60.0)) > 0
ORDER BY   FullName