I need to search rows entered on a specific date.
However the datatype of column I need to search on is datetime, and the datatype of argument is Date.
I can use the the query like
Select result
from table
where
convert(date, Mycolumn) = @selectedDate
but this would affect the SARGability of the query and will not use indexes created on mycolumn.
I was trying to use the following query:
Select result
from table
where
Mycolumn
BETWEEN @selectedDate AND Dateadd(s, -1, Dateadd(D, 1, @selectedDate))
However this does not work since the @selectedDate is Date type and a second can’t be added or removed.
Can someone help me with a working query?
Thanks.
1 Answer