Solved

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

Posted on 2007-04-03
3
254 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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

710 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