Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Filter in Ttable

Posted on 2002-04-01
13
Medium Priority
?
2,178 Views
Last Modified: 2007-12-19
How can i Filter records?

Using -Partial Match Anywhere-

Example

 fName
========
 abc
 sdfa
 sfa
 sfs
 sfdas
 sf
========

filter Field "fName" having the "a" existance in any location
Output:
 
 abc
 sdfa
 sfdas

0
Comment
Question by:girlswants_me
[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
  • 5
  • 4
  • 3
  • +1
13 Comments
 

Author Comment

by:girlswants_me
ID: 6912280
help me please
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6912300
Hello

  You can do that using the Query component with sql statment

  Query1.close;
  Query1.Sql.Text := 'Select * from YourTable where Fname like ' + QuotedStr('%a%');
  Query1.Open;

Best regards
Mohammed Nasman
0
 

Author Comment

by:girlswants_me
ID: 6912308
but im not using the Query component
i used the Property "Filter" in THE Ttable

i want the Filter to do that
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6912330
if you want to use the filter, it will search for the names that start with a like: fname = 'a*', but will not work for names that contain the a
0
 

Author Comment

by:girlswants_me
ID: 6912382
whats wrong with this?

   fmastermodule.Query2.close;
   fmastermodule.Query2.DatabaseName:=DatabaseDirectory;
   fmastermodule.Query2.DataSource:=fmastermodule.dsCOA;
   fmastermodule.Query2.Sql.Text := 'Select * from COA.DB where AccountName = '+''''+FilterValue+'''';
   fmastermodule.Query2.Open;


This will not execute!!!
0
 
LVL 2

Expert Comment

by:isstorr
ID: 6912404
To do a partial match use the 'LIKE' keyword -

SELECT * FROM COA.DB WHERE AccountName LIKE 'a%'

the % is used as a wildcard - this will return all records beginning with an a. For a containing match use -

SELECT * FROM COA.DB WHERE AccountName LIKE '%a%'

Si

PS using a TQuery is generally a lot faster than a TTable with the filter property set.
0
 

Author Comment

by:girlswants_me
ID: 6912422
i think there is a problem with this code
it will not filter records..


whats wrong with this?

  fmastermodule.Query2.close;
  fmastermodule.Query2.DatabaseName:=DatabaseDirectory;
  fmastermodule.Query2.DataSource:=fmastermodule.dsCOA;
  fmastermodule.Query2.Sql.Text := 'SELECT * FROM COA.DB WHERE AccountName LIKE '+''''+'%a%'+'''';
  fmastermodule.Query2.Open;

no results like nothing happen ..


0
 
LVL 2

Accepted Solution

by:
isstorr earned 200 total points
ID: 6912458
This should work -

fmastermodule.Query2.close;
 fmastermodule.Query2.DatabaseName:=DatabaseDirectory;
 fmastermodule.Query2.DataSource:=fmastermodule.dsCOA;
 fmastermodule.Query2.Sql.Text := 'SELECT * FROM COA.DB WHERE AccountName LIKE '"%a%"';
 fmastermodule.Query2.Open;

NB - you should use double quotes for BDE (local SQL) queries and single quotes for ADO queries. Also LIKE is not case sensitive. To get around this use UPPER or LOWER to force case -

fmastermodule.Query2.close;
 fmastermodule.Query2.DatabaseName:=DatabaseDirectory;
 fmastermodule.Query2.DataSource:=fmastermodule.dsCOA;
 fmastermodule.Query2.Sql.Text := 'SELECT * FROM COA.DB WHERE LOWER(AccountName) LIKE '"%a%"';
 fmastermodule.Query2.Open;

Again LOWER and UPPER are BDE specific.
0
 
LVL 2

Expert Comment

by:isstorr
ID: 6912461
sorry I meant LIKE IS case sensitive!
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6912465
Hello

 Like is not case sensetive, and it will run fine with you in the sample I gave you above, use the QuotedStr function to put quations to the string
0
 
LVL 2

Expert Comment

by:isstorr
ID: 6912802
Hmm.. in Local SQL LIKE is definately case sensitive... Open up Database Desktop and run a QBE query you can verify this.
0
 
LVL 4

Expert Comment

by:nestorua
ID: 6913654
HI,
If you want to filter using TTable you could do it as following:
In OnFilterRecord event of you TTable component write this:
Accept:=Pos('a', DataSet.FieldByName('fName').AsString)>0;
Don't forget to put YourTable.Filtered:=True.
And when you change the SubString-to-Filter you must do:
Filtered:=False;
Filtered:=True;
Sincerely,
Nestorua.
0
 

Author Comment

by:girlswants_me
ID: 6914569
Thank you so much
0

Featured Post

Independent Software Vendors: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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