sql server - Subtracting time in SQL query rounding errors -
i have query calculates hours worked dates includes times.
e.g 1/07/2011 7:00:00 - 1/07/2011 5:40:00 pm - 0.5 = 10.166666
the sql is
select entityid, staffid, actualdate, datediff(minute, starttime, endtime) / 60.0 lunch hoursworked dbo.qasitetimesheet starttime , endtime both datetime type. lunch numeric(9,1).
if add whole hours e.g 6:00 - 5:00 pm works fine, add 34, 10, 2 rounds incorrectly.
what doing wrong?
60.0 decimal(3,2) , rules decimal division quite complex.
lunch decimal(9,1) too, can never have more 6 minute accuracy here
put together, it's precision problem.
i'm not going work out (you can see answer here) try this, or explicit cast, or combination
(datediff(minute, starttime, endtime) - (60.0*lunch)) / 60.0 - hoursworked
Comments
Post a Comment