I have a table with a column, [MyDate]
, of datatype DATE
.
I have a variable @MyDateTime DATETIME
.
Is the following comparison:
WHERE [MyDate] < @MyDateTime
semantically equivalent to:
WHERE CONVERT(DATETIME, [MyDate]) < @MyDateTime
(in SQL Server 2012)? (Meaning the two comparisons will always produce the same results.) If not, what is a set of values for which the two are not the same?
This question is motivated by the fact that I observed that the former comparison allows me to more efficiently make use of an index on [MyDate]
while the latter does not.