Re: filer table by a word ....

From: Jeremy Collins (jd.collins_at_ntlworld-not.com)
Date: 03/22/05


Date: Tue, 22 Mar 2005 07:55:59 GMT

sew crazy wrote:

>>Filter := Format('(TypeOfTransport = ''pad'') AND (Distance > %d) ',
>>[DistanceGone]);
>
>
> Is it possible for you to explain this notation espesially the %d
> part?

Format() lets you build a string that contains variables of other
types, without lots of ugly typecasting or calls to conversion
functions. It is extremely useful for building SQL statements.

The %d tells the Format function to replace it with an integer
value; in this case the contents of the DistanceGone variable.

It's a bit daunting at first, but read carefully "Format function"
and "Format strings" in the help file.

>
> how would i filter useing a MonthCalendar - have a field DateIn

Date handling is dependent on your DBMS (and I don't think you've
told us what that is yet). For Access or SQL Server you can usually
treat dates as strings, as long as you use ISO date format.

So something like:

var
   DateStr, SQLStr : string;
begin
   DateStr := FormatDateTime('YYYY-MM-DD', MonthCalendar1.Date);
   SQLStr := Format('SELECT * FROM tb_mytable WHERE DateIn = ''%s''',
[DateStr]);

   :
end;

-- 
jc
Remove the -not from email