amns (8/29/2014)
Hi!I have a datetime column, to which I just need to compare the date part.
Which is the way that performs better to get the rows with a specific date, regardless the time?
Is this a good solution?
DECLARE @DateToFind DATETIME = '2011-11-07 14:40:42.237'; -- (example date)
SELECT Column1, Column2 FROM MyTable
WHERE
DateColumn >= CAST(@DateToFind AS DATE) AND
DateColumn < DATEADD(DAY,1,CAST(@DateToFind AS DATE))
Thanks in advance!
This will also work and will still use an index on DateColumn is it exists:
select
Column1,
Column2
from
dbo.MyTable
where
cast(DateColumn as DATE) = cast(@DateToFind as DATE);
Give it a try and see.