Subject | Finding the longest matching string |
---|---|
Author | Alexander Gräf |
Post date | 2004-11-24T15:06:58Z |
"Tim" <tim@...> schrieb im Newsbeitrag
news:6.1.2.0.0.20041124093604.0825cb28@196.30.30.131...
prefixes:
12
123
1234
1244
14
256
...
Now you want to retrieve "1234". Is that correct?
However, your delphi code looks quite like a SP, I'm sure it can be done
with it, and I would even guess, it could be done with a single SELECT
statement. Take a look at the built-in UDFs in Firebird (InstallDir\udf).
You need to copy the lines from InstallDir\udf\*.sql into your database, to
declare the external functions. There are two functions which would be of
interest for your query, substr and strlen. Try this one
SELECT FIRST(1) PrefixNum FROM PrefixTable WHERE '12345' LIKE PrefixNum ||
'%' ORDER BY strlen(PrefixNum) DESC
I doubt it will work, however you see how you can query the data.
Have fun, Alex
news:6.1.2.0.0.20041124093604.0825cb28@196.30.30.131...
>OK, let me see. You have a number, for example 123456, and a table of
> Hi everyone,
>
> I have an application written in Delphi 5 using dBase files that handles
> EFT transactions for Credit Cards.
>
> Now for the question :
prefixes:
12
123
1234
1244
14
256
...
Now you want to retrieve "1234". Is that correct?
However, your delphi code looks quite like a SP, I'm sure it can be done
with it, and I would even guess, it could be done with a single SELECT
statement. Take a look at the built-in UDFs in Firebird (InstallDir\udf).
You need to copy the lines from InstallDir\udf\*.sql into your database, to
declare the external functions. There are two functions which would be of
interest for your query, substr and strlen. Try this one
SELECT FIRST(1) PrefixNum FROM PrefixTable WHERE '12345' LIKE PrefixNum ||
'%' ORDER BY strlen(PrefixNum) DESC
I doubt it will work, however you see how you can query the data.
Have fun, Alex