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


Relevant Pages

  • printing bits ... the right way
    ... \param str The array of characters where the resulting string is to ... \param format A custom format string specific to converting ... render an integer type into a binary string. ...
    (comp.lang.c)
  • Re: Date format detection
    ... Specifies the locale for which the date string is to be formatted. ... date format for this locale. ... the system default-date format for the specified locale. ... be enclosed within single quotation marks in the date format picture. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Code Guidelines
    ... the built-ins can't really be trusted to work with other code. ... Any code that uses String now has that change. ... `Format` as a noun would seem to be a constructor, ... As lengthy as that namespace is, it does not describe string formatting. ...
    (comp.lang.javascript)
  • Re: Date format detection
    ... > Specifies the locale for which the date string is to be formatted. ... > date format for this locale. ... > the system default-date format for the specified locale. ... > be enclosed within single quotation marks in the date format picture. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: ADP ignoring my format code
    ... The Value property of the textbox, which is a Variant, is converted by the ... Format function to a Variant of sub-type String, ...
    (microsoft.public.access.adp.sqlserver)