Answer the question
In order to leave comments, you need to log in
How to do sql select by date?
Hello everyone!
I need to count the number of records in a table for a certain number. There is a date field for this. But the date is written in this format - 2020-07-07 15:01:38.950
Tried like this
SELECT COUNT(*) FROM [Table] WITH(NOLOCK) WHERE UpdateDate = '06.06.2020'
Answer the question
In order to leave comments, you need to log in
SELECT COUNT(*) FROM [Table]
WHERE CAST( UpdateDate AS DATE) = '20200606'
It seems to me that by pushing the field into the function of casting the type or date, you have killed the use of the index on the field.
I suggest the author to check this moment. If I turned out to be right, then to use the index, you need to put a fork of values and leave the field itself:
where UpdateDate >= :date and UpdateDate < date_add(:date, interval 1 day)
-- :date - полночь необходимой даты
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question