Mega Search
23.2 Million


Sign Up

Make a donation  
Fi;ter using wildcard  
News Group: embarcadero.public.delphi.install

I need to filter a DBGrid on a column of emails. I want to filter on the first letter. For example if the email is sam@Yahoo,com, I want to display all emails tha start with the letter ‘s’.  All of the emails have been converted to lower case.
Here is my code:

    Form_Main.AdoTable2.First;
    FilterVal := copy(email,1,1);
    Filter    := 'email = ' + QuotedStr('FilterVal*');
    Filtered := true;

FilterVal returns the first letter of the email address.
The program runs but there are no emails listed in the DBGrid. If I set the Filtered to false all emails are listed.
What is the problem with my Filter statement?

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 5-Dec-2014, at 3:33 PM EST
From: Mervin Norton
 
Re: Fi;ter using wildcard  
News Group: embarcadero.public.delphi.install
Mervin wrote:

> What is the problem with my Filter statement?

You want to do a substring search, but you are using the '=' SQL operator, 
which does an exact match comparison.  You need to use the 'LIKE' operator 
instead (with the '%' wildcard, not '*'), and you are not passing your FilterVal 
to QuoteStr() correctly, either.

Try this instead:

{code}
Form_Main.AdoTable2.First;
FilterVal := Copy(email,1,1);
Filter    := 'email LIKE ' + QuotedStr(FilterVal+'%');
Filtered := true;
{code}

--
Remy Lebeau (TeamB)

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 5-Dec-2014, at 4:04 PM EST
From: Remy Lebeau (TeamB)