Solved

Using Filter in Ttable

Posted on 2002-04-01
13
2,170 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now