我有以下声明
select pkid
from AttendancePosting
where datename(dw,AttDate) = 'Sunday' and empid=4 and attdate='2015-12-13'
group by PKId,timeout
--having 9=9
having cast(sum((datepart(minute, timeout)))/2 as float )+''=cast(datepart(minute,timeout) as float) +''
问题是
having cast(sum((datepart(minute, timeout)))/2 as float )+''=cast(datepart(minute,timeout) as float) +''
不工作。 cast(sum((datepart(minute, timeout)))/2 as float )
和cast(datepart(minute,timeout) as float)
都带来相同的值,但select语句仍未获取任何记录,两者都返回9
我已经像这样检查了它
select pkid
from AttendancePosting
where datename(dw,AttDate) = 'Sunday' and empid=4 and attdate='2015-12-13'
group by PKId,timeout
having 9=9
它带来的记录,任何帮助将不胜感激。
答案 0 :(得分:1)
首先,您的语句datepart(minute, timeout)/2
将返回一个整数。您可以通过更精确地使SQL Server变得更加精确datepart(minute, timeout)/2.
。
其次,浮点数是近似值。您最好使用ROUND()
并指定您认为合适的小数位数。例如:round(sum((datepart(minute, timeout)))/2.0, 3)
。