[Asterisk-Users] Re: OT : For the SQL gurus..
Reinhard Max
max at suse.de
Tue Nov 11 01:54:44 MST 2003
On Mon, 10 Nov 2003 at 10:17, brez wrote:
> > SELECT *, length(code)
> > FROM a
> > WHERE code = '00442085673456'
> > OR code = '0044208567345'
> > OR code = '004420856734'
> > OR code = '00442085673'
> > OR code = '0044208567'
> > OR code = '004420856'
> > OR code = '00442085'
> > OR code = '0044208'
> > OR code = '004420'
> > OR code = '00442'
> > OR code = '0044'
> > ORDER BY length(code) DESC;
> >Again, the first row in the result set is the one you are after.
>
> can be reduced to:
>
> SELECT TOP 1 *, length(code)
> FROM a
> WHERE code LIKE '0044%'
> ORDER BY length(code) DESC;
No it can't, because that would bring up everything that starts with
0044 (e.g. 00445678), but we are looking for the longest prefix that
matches a given number.
cu
Reinhard
More information about the asterisk-users
mailing list