with qryProject_ do
begin
Active := False;
SQL.Clear;
SQL.Text := 'SELECT * FROM TODO WHERE ';
case rgFilterOptions.ItemIndex of
0 : SQL.Add('TODO.DateCompleted <> null ');
1 : SQL.Add('TODO.DateCompleted = NULL ');
end;
SQL.Add('AND TODO.SECTION = :sSec ');
SQL.Add('AND TODO.DateCreated BETWEEN :sStart AND TODO.DateCreated <= :sEnd');
SQL.Add(' ORDER BY TODO.DateCreated');
Params.ParamByName('sSec').AsString := qrySection_Section.AsString;
Params.ParamByName('sStart').AsString := FormatDateTime('yyyy-mm-dd', dtpStart.Date);
Params.ParamByName('sEnd').AsString := FormatDateTime('yyyy-mm-dd',dtpEnd.Date);
Active := True;
End;
End;
CREATE TABLE ToDo
(
UID INTEGER NOT NULL,
Subject CHAR(20),
SECTION CHAR(10),
Details BLOB,
FileName CHAR(20),
DateCreated CHAR(10) DEFAULT NULL,
DateCompleted CHAR(10) DEFAULT NULL,
CONSTRAINT PK_ToDo PRIMARY KEY (UID)
Right, as already said in your other thread (and mentioned by gsa)
case rgFilterOptions.ItemIndex of
0 : SQL.Add('TODO.DateCompleted <> null ');
1 : SQL.Add('TODO.DateCompleted = NULL ');
You cannot compare/filter directly on NULL. Period!
This never returns records.
gsa showed the correct syntax
SQL.Add('AND TODO.DateCreated BETWEEN :sStart AND TODO.DateCreated <= :sEnd');
This is wrong. You're looking for DateCreated between :sStart and a Boolean, because SQL interprets this as a Boolean: TODO.DateCreated <= :sEnd
pawel already showed you the correct syntax.
I'm more surprised this doesn't throw a syntax-error
I'm using Date-Fields in SQLite extensively, and never had a problem, provided you USE the correct format in the Database itself, which should always be "YYYY-MM-DD" as Text/Char and nothing else.
On a sidenote: If you use the BETWEEN-Operator in your WHERE-Clause, the LEFT Parameter MUST be lower/equal than the RIGHT Parameter
A ".... MyDate BETWEEN '2026-06-16' AND '2026-03-13' will never return records, even if you have records falling into that time-window
EDIT: hmmm...maybe this is actually what happened:
I'm more surprised this doesn't throw a syntax-error
The right-hand-side of the BETWEEN is evaluated as Boolean, which returns "0" or "1" as an Integer.
The left-hand-side receives a valid value for sStart, which is >0/1, or worse: left hand side is a String, right hand-side is a boolean/Integer
When we account for implicit casting of right-hand-side from boolean/Integer to String...
and then we would have the above scenario:
left-parameter Greater than right parameter --> No results
EDIT2: Remember: BETWEEN is inclusive of the boundaries.
If you need even one boundary excluded, you can't use BETWEEN, but you need to write it out