Solved

Using Filter in Ttable

Posted on 2002-04-01
13
2,169 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
Comment Utility
help me please
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
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
Comment Utility
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:mnasman
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:girlswants_me
Comment Utility
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
Comment Utility
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
Comment Utility
sorry I meant LIKE IS case sensitive!
0
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you so much
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now