[英]Where clause fails if using same date in a “greater than or equal to” and a “less than or equal to”
Why does this query not return any rows when date1
, date2
, and dateField
are the same and there are rows where dateField == date1
that should be returned? 为什么当
date1
, date2
和dateField
相同且有应返回dateField == date1
行时,此查询不返回任何行?
Examples: 例子:
select * from tableName where dateField >= date1 and dateField <= date2
It appears that the time part of the smalldatetime
field dateField
used to be all zeros, and now it's not. 看来
smalldatetime
字段dateField
的时间部分以前全为零,现在不是。 The solution was to just compare the date portion of dateField
. 解决方案是只比较
dateField
的日期部分。
SELECT *
FROM tableName
WHERE
CONVERT(DATE, dateField) >= date1 AND CONVERT(DATE, dateField) <= date2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.