Convert SQL server datetime fields to compare date parts only, with indexed lookups
Posted
by Caveatrob
on Stack Overflow
See other posts from Stack Overflow
or by Caveatrob
Published on 2008-12-09T14:59:53Z
Indexed on
2010/06/16
4:22 UTC
Read the original article
Hit count: 321
I've been doing a convert(varchar,datefield,112) on each date field that I'm using in 'between' queries in SQL server to ensure that I'm only accounting for dates and not missing any based on the time part of datetime fields.
Now, I'm hearing that the converts aren't indexable and that there are better methods, in SQL Server 2005, to compare the date part of datetimes in a query to determine if dates fall in a range.
What is the optimal, indexable, method of doing something like this:
select * from appointments where appointmentDate>='08-01-2008' and appointmentDate<'08-15-2008'
© Stack Overflow or respective owner