I’m sure this is a VERY simple problem, but I’ve not been able to figure it out. Here’s my query:
select column1 from table1 with(nolock)
where column1 like '2011-07-0[78]%'
order by column1 desc
As you can tell, I’m querying a row looking for timestamps that are from either today or yesterday.
A full timestamp within one of these rows looks like this:
2011-07-08 12:16:39.553
I’ve done similar things many times with no trouble, but the above query returns no results no matter what I try. (Yes, there are timestamps from today and yesterday in the column).
Have I made a syntax error? Am I crazy? Are there gnomes in my DB messing with my query? Please help! Thank you so much!
If the datatype for that field is
datetimeorsmalldatetimethenLIKEwon’t work as expected.You could do a
DATEPARTfunction orBETWEEN, like:or
WHERE column1 BETWEEN '2011-07-07' AND '2011-07-08'Bear in mind
BETWEENis inclusive.