C
C
CityzenUNDEAD2020-07-07 15:17:15
SQL
CityzenUNDEAD, 2020-07-07 15:17:15

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'

Tried with like.

Did not work.
How can I select by date?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2020-07-07
@CityzenUNDEAD

SELECT COUNT(*) FROM [Table] 
  WHERE CAST( UpdateDate AS DATE) = '20200606'

A
Andrey, 2020-07-07
@AndryG

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 question

Ask a Question

731 491 924 answers to any question