Page 1 of 1

TMyStoredProc / Filter property does not work with LIKE clause ?

Posted: Wed 02 Aug 2006 15:57
by jackfirst72
Hi,
Here is the code I use to filter the content of my TMyStoredProc after having retrieved data from the database :
---------------------------------------------------------------------------------

Code: Select all

procedure MyOwnClass.ExecuteFilter(const pc_valueToSearch : String);
var
  FilterValue : String;
begin
  if (pc_valueToSearch = EmptyStr) then
  begin
    FilterValue := EmptyStr;
  end
  else
  begin
    FilterValue := 'aFieldName LIKE ' + QuotedStr('%' + pc_valueToSearch + '%');
  end;
  pxyMySPMaster.Filtered := false;
  pxyMySPMaster.Filter   := FilterValue;
  pxyMySPMaster.Filtered := true;
end;
---------------------------------------------------------------------------------
The result is just empty ??? But the exactly same code DOES work with a simple TClientDataSet with the same columns and data ?
Thanks for your help.

Posted: Wed 02 Aug 2006 17:34
by jackfirst72
I forgot to say that the comparison '=' works fine. So if I write the following

Code: Select all

...
FilterValue := 'aFieldName = ' + QuotedStr(pc_valueToSearch);
...
and that "valueToSearch" corresponds exactly, the result is OK.
Why does'nt it work with the LIKE clause ?
Thanks.

Posted: Thu 03 Aug 2006 11:04
by Jackson
Try to use '*' wildcard instead of '%'.

Posted: Thu 03 Aug 2006 13:03
by jackfirst72
Hi EvgeniyM.
Thanks for the tip. It works fine.
Have a good development day. :D