Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Building a query to search registers in date Incorrect syntax near '='

I am trying to find all the recorded on a specific date, my date column is of type datetime.

I can’t understand why it’s giving me this error

SELECT * 
FROM dbo.Clientes
WHERE registrado = CONVERT(DATE,registrado) = '2022-10-20'
ORDER BY ID DESC

Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ‘=’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try too much "="

SELECT *
FROM dbo.Clientes
WHERE CONVERT(DATE,registrado) = '2022-10-20'
ORDER BY ID DESC

To be honest I prefer the use of "CAST" instead of "CONVERT"

SELECT *
FROM dbo.Clientes
WHERE CAST(registrado AS DATE) = '2022-10-20'
ORDER BY ID DESC
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading