Manuel Lopez-Michelone
asked on
how to search (filter) substrings using a query component in a BDE database?
I have a BDE database with three fields: two memos and one string field. I want to searchand filter the string field to find partial strings. I mean, I want to filter the database (and to see the results in a dbgrid who is present in my form) if I search for the string "nd". The system should show me the records with this specific field 'nd', for instance 'random' or 'and', but hide records with 'hello' string...
I tried this:
Query1.Active:=false;
Query1.Sql.Clear;
Query1.Sql.Add('select * from database where field like '+QuotedStr('%'+SearchStr+ '%'));
Query1.Active:=true;
but it didnt work...Any ideas what I am doing wrong? Should I have the string field indexed?
I tried this:
Query1.Active:=false;
Query1.Sql.Clear;
Query1.Sql.Add('select * from database where field like '+QuotedStr('%'+SearchStr+
Query1.Active:=true;
but it didnt work...Any ideas what I am doing wrong? Should I have the string field indexed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot. Simple answer and very useful...
regards
Lopem
regards
Lopem
Try this way:
with Query do
begin
Close;
Sql.Clear;
Sql.add('select * from database where field like :p');
Parambyname('p').asstring := '%' +SearchStr+ '%';
Open;
end;
Steve