Solved

Using Filter in Ttable

Posted on 2002-04-01
13
2,174 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
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!

 
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

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 79
When i run adoquery my application freezes 26 191
Firemonkey webbrowser scrollbars ? 1 57
enhance the following code 3 42
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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