I have such a simple question, I feel stupid for asking it. I can’t believe I’m hitting my head on this.
I have a table called “Orders”. “Orders” has a smalldatetime field called “DateOrdered”. I need to get all of the “Orders” on a specific date. I have tried the following without any success:
SELECT * FROM Orders WHERE [DateOrdered]=2010-06-01
SELECT * FROM Orders WHERE [DateOrdered]='2010-06-01'
SELECT * FROM Orders WHERE [DateOrdered]=CAST('2010-06-01' AS smalldatetime)
What am I doing wrong? I can’t believe I’m even asking this question.
The first query compares the date to the number
2003(2010 minus 6 minus 1) which converts into the date'1905-06-27'. The second and third query would work for exact date values (i.e. with a 00:00 time component), and are equivalent.Do you have a time component in your smalldatetime values? In that case you can get the values in an interval:
Notice the use of
>=and<instead of thebetweenkeyword, to exclude any records that might have the exact value2010-06-02.