Subject Re: Select based on a partial match
Author Raúl Alberto Valencia Najarro
Sure. Just use the SQL LIKE Operator:

SELECT s.TAXNAME, t.TAXVAL FROM SALESREG s, TAXTBL t
WHERE s.TAXNAME LIKE 'CO%'

OR

SELECT s.TAXNAME, t.TAXVAL FROM SALESREG s, TAXTBL t
WHERE s.TAXNAME LIKE 'IL%'

The percentage sign (%) acts as a wildcard.

You can also consult the documentation for:

value STARTING value
value NOT STARTING value
value STARTING WITH value
value NOT STARTING WITH

Cheers.

Raúl.


--- In firebird-support@yahoogroups.com, "Dixon Epperson"
<edepperson@j...> wrote:
> Is there a way to do a select statement where field one matches part
> of field2?
>
> example
> SELECT s.TAXNAME, t.TAXVAL FROM SALESREG s, TAXTBL t
> WHERE s.TAXNAME[1,2]=t.NAME
>
> SALESREG.TAXNAME WOULD BE A CHAR(6), IT COULD HOLD UP TO THREE
> 2 CHARACTER TAX NAME SUCH AS 'ILCOCC'.
> 'IL' WOULD BE ILLINOIS, 'CO'WOULD BE COOK COUNTY, AND 'CC' WOULD BE
> CHICAGO CITY.
>
> I WOULD NEED TO GET THE TAX VALUE FOR 'IL', FOR 'CO' AND 'CC'.
>
> IN DELPHI I WOULD USE A FUNCTION LIKE COPY(s.TAXNAME, 1,2) TO GET THE
> FIRST 2 CHARACTER, COPY(s.TAXNAME, 3,2) FOR THE TWO MIDDLE ONES, ETC.
>
> IS THERE AN SQL FUNCTION IN FIREBIRD THAT WILL ALLOW THAT?
>
> Dixon Epperson