select *
from dbo.March2010 A
where A.Date >= Convert(datetime, '2010-04-01' )
In your query, 2010-4-01
is treated as a mathematical expression, so in essence it read
(在您的查询中, 2010-4-01
被视为数学表达式,因此本质上它是读取的)
select *
from dbo.March2010 A
where A.Date >= 2005;
( 2010 minus 4 minus 1 is 2005
Converting it to a proper datetime
, and using single quotes will fix this issue.)
(( 2010 minus 4 minus 1 is 2005
将其转换为正确的datetime
,并使用单引号将解决此问题。))
Technically, the parser might allow you to get away with
(从技术上讲,解析器可能允许你逃脱)
select *
from dbo.March2010 A
where A.Date >= '2010-04-01'
it will do the conversion for you, but in my opinion it is less readable than explicitly converting to a DateTime
for the maintenance programmer that will come after you.
(它会为你做转换,但在我看来,它比你明确转换为维护程序员的DateTime
更不易读。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…