I am receiving unexpected results from an SQL SELECT statement in my Delphi 12.3 app. I believe the SQL statement is properly formatted, however, I get no records.
I tested the following SQL statements and they returned the appropriate results:
SELECT * FROM ExpGenItem;
SELECT * FROM ExpGenItem INDEXED BY idx_pdate;
When I executed the following SQL statement, I receive no results (I should get 5-6):
SELECT *
FROM ExpGenItem INDEXED BY idx_pdate
WHERE ExpDate BETWEEN '07/01/2025' AND '07/15/2025';
The ExpDate column in the SQL datebase is of type DATE, and the application code uses two TDateTimePicker controls to generate the start/end dates for the SQL statement.
Here is the code that builds the SQL statement and executes it. Where RepStateDate and RepEndDate are both TDateTime types. The function etStrQuote() simply appends the single quote mark (') to the date strings.
sqltxt:='SELECT * FROM ExpGenItem INDEXED BY idx_pdate WHERE ';
sqltxt:=sqltxt+'ExpDate BETWEEN '+etStrQuote(DateToStr(RepStartDate))+' ';
sqltxt:=sqltxt+'AND '+etStrQuote(DateToStr(RepEndDate))+';';
dmData1.ExpItemQuery.SQL.Text:=sqltxt;
dmData1.ExpItemQuery.Open;
07/01/2025means - is that January 7th? Or July 1st? You only have assumptions. While SQLite has no real date type, if dates are stored as strings, they MUST be in ISO8601 format, ieYYYY-MM-DD. This will never match the ambiguous localized string07/01/2025. Store dates properly and use actual date-typed parameters. SQLite will handle the rest