Solved

how to search (filter) substrings using a query component in a BDE database?

Posted on 2007-04-03
3
252 Views
Last Modified: 2010-04-05
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?
0
Comment
Question by:lopem
3 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 50 total points
ID: 18848728
normally in SQL you can use "like" as in
select * from table1 where FirstName like '%something%'
the % being a wildcard
However, I don't think BDE supports this.
You could however, use the "OnFilter" event.
set the "filtered" property to true and then in the onfilter event you use
Accept := (pos(edit1.text, dataset.FieldByName('SomeField').AsString > 0);
0
 
LVL 6

Expert Comment

by:bokist
ID: 18848999
Hi !
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
0
 
LVL 3

Author Comment

by:lopem
ID: 18851494
Thanks a lot. Simple answer and very useful...

regards
Lopem
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question