Thanks for all those who helped me with this a few days ago (I've only now
had the chance to get back to programming).
As someone correctly surmised, I am using Delphi and connecting to mySQL via
a TQuery (actually a TZQuery, via Zeos components). What I have discovered
1. mySQL doesn't like queries with date parameters (one must pass the date
as a literal)
2. the date format has to be changed to that of mySQL.
3. if one uses a table alias ("p" in my case), one is not allowed to use the
full table name - "projects.closeddate" causes an error, but p.closeddate is
So I wrote a small function (called date2sql) which turns 18/12/2003 into
"2003-12-18" (complete with double quotation marks), and then in my code I
with query1 do
sql:= 'where p.closeddate between ' + date2sql (edFromDate.text) + ' and
' + date2sql (edTillDate.text);
This works as it should.
From: Martijn Tonies [mailto:m.tonies@stripped]
Sent: Tuesday, December 16, 2003 4:47 PM
Subject: Re: Re: Comparing date fields
> mysql>> select projects.name from projects
> JB> -> where projects.closeddate between :fd and :td;
> JB> ERROR 1064: You have an error in your SQL syntax near ':fd and :td' at
> JB> line
> JB> 2
> JB> What are those colons?
> He probably uses Delphi or C++Builder to connect to mysql via TQuery
> component. TQuery has a property SQL where sql statement is stored.
> The colon ':' means that fd is a parameter whose value should be
> inserted into TQuery.SQL statement just before executing the query.
> The solution is to substitute :fd with a real value directly by accessing
> Query.SQL.Add('select ...');
> Query.SQL.Add('where projects.closeddate between 01/01/01 and 01/01/02');
I very much doubt this works:
01 divided by 01 :-)
I guess you wanted to write:
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql