2005. október 28., péntek

How to filter on substrings within a string field's value


Problem/Question/Abstract:

How to filter on substrings within a string field's value

Answer:

In the TTable OnFilter event:

var
  sp, ss: ShortString
begin
  with DataSet do
  begin
    sp := FilterPosition.Text; {TEdit containing substring to be filtered}
    ss := AnsiUpperCase(FieldByName('MyField').asString);
    Accept := Pos(sp, ss) > 0;
  end;
end;

or with an SQL script:

SELECT * FROM MyTable
WHERE UPPER(MyField)LIKE "%UPPER(MySubstring)%";

Nincsenek megjegyzések:

Megjegyzés küldése