How to Search datetime in Sql server 2008R2 -
i having problem sql search . trying search help of datetime because in project time important. when utilize query this
where registration_date = '2014-06-19 00:12:08.940' it works seek search using
where registration_date '2014-06-19%' i no results. because want search registration taken place on specific date including time, assuming dont know specific time...
you have cast date compare 2 dates on equality. eg
cast(registration_date date) = cast('2014-06-19' date) an alternative:
declare @datetofilter date = (cast('2014-06-19' date)) [..] registration_date >= @datetofilter , registration_date < dateadd(d, 1, @datetofilter) edit: regarding performance, , assuming index exists on date column, index can used in both cases (yes, cast(x date) sargable). there interesting analysis on performance differences here , here. always, test.
sql sql-server datetime
No comments:
Post a Comment