Subject Re: [firebird-support] Re: Select based on a partial match
Author Helen Borrie
At 01:35 PM 17/02/2004 +0000, you wrote:
> > SELECT s.TAXNAME, t.TAXVAL FROM SALESREG s, TAXTBL t
> > WHERE s.TAXNAME LIKE 'CO%'
> >
>Raul,
>
>thats not what I'm looking for. I did find the SUBSTR UDF, and have
>been experiementing with it, but don't know how to setup and use a
>UDF
>
>Example
>SELECT * FROM SALESDETAIL s WHERE SUBSTR(s.SD_TAXCODE, 3,2)='CO'
>
>sd_taxcode might be 'IL '
>or it could be 'ILCO '
>or it could be 'ILCOCC'
>
>is SubStr the right idea here and how do you implement a UDF.

If you are using Firebird, it has an internal SQL SUBTSTRING function:

SELECT * FROM SALESDETAIL s
WHERE SUBSTRING(s.SD_TAXCODE FROM 3 FOR 2)='CO'

Won't work for InterBase though. So, for IB, use the subtsr() function from
ib_udf.

1. Open ib_udf.dll in the delphi editor and copy the declaration
2. Paste it into a DDL script and don't forget to end the declaration with
";".
3. Press the Return key at least once after the end of the declaration.
4. Save the script.
5. Run it in isql.
6. commit it.

(There are other ways. :-) )

Once it's there just use it like any other function.

You have to watch your usage of substr() in the InterBase version. It's
syntax is a bit flaky. See the IB LangRef.

/hb