Subject | Re: [firebird-support] SQL Question |
---|---|
Author | Alexandre Benson Smith |
Post date | 2005-12-06T23:26:20Z |
Fabio Gomes wrote:
I think with this design you will not get anything ellegant. :-(
A very crude way that will work will be
select
Max(cast(Field as integer)) + 1
from
Table
where
Field between '0' and '999999999999' and -- this should speed the
things up if you have an index on the field
(substring(field from 1 for 1) between '0' and '9' or Substring(field
from 1 for 1) = '') and
(substring(field from 2 for 1) between '0' and '9' or Substring(field
from 2 for 1) = '') and
(substring(field from 3 for 1) between '0' and '9' or Substring(field
from 3 for 1) = '') and
(substring(field from 4 for 1) between '0' and '9' or Substring(field
from 4 for 1) = '') and
(substring(field from 5 for 1) between '0' and '9' or Substring(field
from 5 for 1) = '') and
(substring(field from 6 for 1) between '0' and '9' or Substring(field
from 6 for 1) = '') and
(substring(field from 7 for 1) between '0' and '9' or Substring(field
from 7 for 1) = '') and
(substring(field from 8 for 1) between '0' and '9' or Substring(field
from 8 for 1) = '') and
(substring(field from 9 for 1) between '0' and '9' or Substring(field
from 9 for 1) = '') and
(substring(field from 10 for 1) between '0' and '9' or
Substring(field from 10 for 1) = '') and
(substring(field from 11 for 1) between '0' and '9' or
Substring(field from 11 for 1) = '') and
(substring(field from 12 for 1) between '0' and '9' or
Substring(field from 12 for 1) = '') and
(substring(field from 13 for 1) between '0' and '9' or
Substring(field from 13 for 1) = '')
ugly ugly ugly !
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br
>I m newbie in sql, but i did something similar like this:this will return tha same as the original query.
>
>SELECT FIRST 1 ClientCode
>FROM Client
>WHERE ClientCode < 'A'
>ORDER BY ClientCode DESC
>
>btw.. i dont know if its gonna work.. it was just what came to my mind >D
>
>
I think with this design you will not get anything ellegant. :-(
A very crude way that will work will be
select
Max(cast(Field as integer)) + 1
from
Table
where
Field between '0' and '999999999999' and -- this should speed the
things up if you have an index on the field
(substring(field from 1 for 1) between '0' and '9' or Substring(field
from 1 for 1) = '') and
(substring(field from 2 for 1) between '0' and '9' or Substring(field
from 2 for 1) = '') and
(substring(field from 3 for 1) between '0' and '9' or Substring(field
from 3 for 1) = '') and
(substring(field from 4 for 1) between '0' and '9' or Substring(field
from 4 for 1) = '') and
(substring(field from 5 for 1) between '0' and '9' or Substring(field
from 5 for 1) = '') and
(substring(field from 6 for 1) between '0' and '9' or Substring(field
from 6 for 1) = '') and
(substring(field from 7 for 1) between '0' and '9' or Substring(field
from 7 for 1) = '') and
(substring(field from 8 for 1) between '0' and '9' or Substring(field
from 8 for 1) = '') and
(substring(field from 9 for 1) between '0' and '9' or Substring(field
from 9 for 1) = '') and
(substring(field from 10 for 1) between '0' and '9' or
Substring(field from 10 for 1) = '') and
(substring(field from 11 for 1) between '0' and '9' or
Substring(field from 11 for 1) = '') and
(substring(field from 12 for 1) between '0' and '9' or
Substring(field from 12 for 1) = '') and
(substring(field from 13 for 1) between '0' and '9' or
Substring(field from 13 for 1) = '')
ugly ugly ugly !
see you !
--
Alexandre Benson Smith
Development
THOR Software e Comercial Ltda
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br