I need to query SQLite datebase table using the following SQL Statement.
SELECT *
FROM Alarms
WHERE ALARMSTATE IN (0,1,2)
AND ALARMPRIORITY IN (0,1,2,3,4)
AND ALARMGROUP IN (0,1,2,3,4,5,6,7)
AND DateTime(ALARMTIME) BETWEEN datetime("2012-08-02 00:00:00")
AND datetime("2012-08-03 00:00:00")
ORDER BY ALARMTIME DESC
ALARMTIME is of TEXT datatype.
ALARMTIME is displayed in the datagridview as follow “08/03/2012 11:52 AM”. Can you use that format for checking like DateTime(ALARMTIME)?
The only problem have with this SQL Statement is that it always returns zero dataset or records. However, SQLite doesn’t complain about the syntax.
Strictly speaking, SQLite doesn’t have datetime types for its columns:
The problem here is that the string you’re using condition isn’t a valid date/time, so it’s treated as null:
(Note
2012-08-03instead of2012-08-3.)In addition, make sure that the values in your
ALARMTIMEare correctly formatted too.