T-SQL 查询返回不应该的项目 [英] T-SQL Query Returning Items It Shouldn't Be
本文介绍了T-SQL 查询返回不应该的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是场景.有问题的列称为datein",其类型为datetime".对于datein",我有三行的值为2009-10-01 00:00:00.000".为什么此查询会返回上述行?
Here's the scenario. The column in question is called 'datein' and it's type is 'datetime'. I have three rows with the value of '2009-10-01 00:00:00.000' for 'datein'. Why does this query return the aforementioned rows?
SELECT *
FROM t_call AS tc
WHERE tc.datein >= '2009-09-30 00:00:00.000'
AND tc.datein <= '2009-09-30 23:59:59.999'
使用
SELECT *
FROM t_call AS tc
WHERE tc.datein BETWEEN '2009-09-30 00:00:00.000'
AND '2009-09-30 23:59:59.999'
返回相同的结果
推荐答案
缺乏千分之一秒值的精度.试试.997".
It's the lack of precision in the thousandths of a second value. Try ".997" instead.
运行这个,你会看到:
declare @dt datetime
select @dt = '2009-09-30 23:59:59.999'
select @dt
这篇关于T-SQL 查询返回不应该的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文