TSQL不等于<&燃气轮机;表现不同

TSQL不等于<&燃气轮机;表现不同,sql,tsql,sql-server-2008-r2,Sql,Tsql,Sql Server 2008 R2,我在SQLServer2008R2中有两个表 TABLE1 - Column DateCreated datetime null TABLE2 - Column DateCreated datetime null When I see the profiler SELECT * from TABLE1 WHERE DateCreated <> '2011-06-10 00:00:00.000' 没有返回任何记录 关于表2 SELECT * from TABLE2 WHERE Da

我在SQLServer2008R2中有两个表

TABLE1 - Column DateCreated datetime null
TABLE2 - Column DateCreated datetime null

When I see the profiler
SELECT * from TABLE1
WHERE DateCreated <> '2011-06-10 00:00:00.000'
没有返回任何记录

关于表2

SELECT * from TABLE2
WHERE DateCreated <> '2011-06-10 00:00:00.000'

所有3条记录都将返回。这很奇怪。为什么在第一种情况下,当我应该取回一条记录时,我没有取回任何记录???

在您的SQL中,“2011-06-10 00:00:00.000”不是日期。它是一个转换为日期的字符串。在数据库中,“2011-06-10 00:00:00.000”实际上可能是“2011-06-10 00:00:00.00001”。也许可以尝试使用DATEDIFF(mcs,DateCreated,'2011-06-10 00:00:00.000')看看实际的差异是什么

我无法复制它:您能在查询之前尝试执行以下操作吗:set dateformat ymdTried Agnius但不工作QLServer使用大约3毫秒的分辨率(最后一位数字为0、3或7),因此特定的日期字符串应该准确转换。看看datediff(mcs提供,我不能使用datediff,因为我正在使用动态Linq生成这些sql查询,我正在从sql探查器粘贴这些sql查询。你不能从探查器复制sql,编辑它并通过查询分析器(或SSMS)运行吗?是的。但是将datediff添加到查询中。类似于:选择*,datediff(mcs,'2011-06-10 00:00:00.000',DateCreated)表1中的日期创建于“2011-06-09 23:59:00.000”和“2011-06-10 00:01:00.000”之间
SELECT * from TABLE2
WHERE DateCreated <> '2011-06-10 00:00:00.000'
2011-06-10 18:02:05.000
2011-06-10 18:05:08.000
2011-06-10 18:07:09.000