I'm new here and I don't know if this has been asked earlier, but I've
strugled almost whole day trying to use variable (including date-data)
SQL-stament.
Fos example, if I use:
'SELECT * FROM MyTable WHERE MyDateField <= ''11/19/1996'''
it works fine and shows all the records that are older or equal to above
date.
How can I put a variable in the place where I have the "11/19/1996"
Regards,
Two main methods. First, use a parameter. I don't use those that often,
but the idea is in the SQL use:
Select * from MyTable where MyDateField <= :MyDate
then set the params property of the query to your value.
A more flexible method is to modify the SQL property of the query in code.
For example, in response to a buttock click (or form activate or form
show):
with Query1 do begin
SQL.clear;
SQL.add('select * from MyTable where MyDateField <= "' +
edit1.text+'"');
active := True;
end;
This takes the text of the Edit box (Edit1.text) and puts it into the
query, then activates the query. This method allows a great deal of
flexibility in creating complex queries.
> Fos example, if I use:
> 'SELECT * FROM MyTable WHERE MyDateField <= ''11/19/1996'''
> How can I put a variable in the place where I have the "11/19/1996"
try:
'SELECT * FROM MyTable WHERE MyDateField <= :anydate'
Qry.ParamByName('anydate').AsString := '01/01/97';
then run the query...
or
Qry.ParamByName('anydate').AsDateTime := now;
reguards guenther
Aimo Aronen <aim...@netti.fi> wrote in article <32A35B...@netti.fi>...
> Hi all !
>
> I'm new here and I don't know if this has been asked earlier, but I've
> strugled almost whole day trying to use variable (including date-data)
> SQL-stament.
>
> Fos example, if I use:
> 'SELECT * FROM MyTable WHERE MyDateField <= ''11/19/1996'''
> it works fine and shows all the records that are older or equal to above
> date.
>
> How can I put a variable in the place where I have the "11/19/1996"
>
> Regards,
>
You had to worked with params ex :
your SQL statements should look like that
SELECT * FROM MyTable
WHERE MyDateField =: DateVar
And in the properties Params of your SQL
you should have a DateVar Declared
After that the SQL will be call by :
SQL.close;
Q.ParamByName('DateVar').AsDateTime := StrToDateTime (YourDate);
Q.Open;
Benoit Courchesne
Universite du Quebec a Montreal
Departement d'informatique
df19...@er.uqam.ca