I am using SqlServer Compact 3.5 (2008) and am trying to return rows that have a datetime field that is today or previous. This is the code I am trying, but it is throwing an exception. (in the Where clause)
I’m new to SQL so I’m having trouble with this one. Any ideas? If you need more data, let me know.
string selectStatement =
"SELECT * FROM EnglishSpanish ORDER BY AvgScore DESC " +
"WHERE NextShow <= @Today";
SqlCeCommand selectCommand = new SqlCeCommand(selectStatement, connection);
selectCommand.Parameters.AddWithValue("@Today", DateTime.Today);
The “ORDER BY” clause must come after the “WHERE” clause. The SQL statement should read
Also notice that I am using “<” instead of “<=”. Instead of using
DateTime.Todayyou should useDateTime.Today.AddDays(1)becauseDateTime.Todaywill give you ‘2010-07-29 00:00:00’ which is midnight between July 28th and 29th. Hence your clause will not give you the records of today.