Solved

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

Posted on 2007-04-03
3
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month5 days, 12 hours left to enroll

627 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