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
Solved

Using Filter in Ttable

Posted on 2002-04-01
13
2,173 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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 50 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

789 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