Subject AW: [firebird-support] string seperation
Author Olaf Kluge
Hello,



many Thanks. It works with substring and position!


>
> I receive a string like this " 123x22" or "1x3333"
>
> The signs in front of 'x' should I insert into a separate Variable, also
the
> signs after 'x'
>
> How can I separate this in firebird? Substring is not the right, because
no
> fixed length.

Why not substring, Olaf?

I mean, as long as the variable is relatively short, you can at least write
something like

UPDATE MyTable
SET MyPart1 = case when substring(MyXField from 1 for 1) = 'x' then ''
when substring(MyXField from 2 for 1) = 'x' then substring(MyXField from 1
for 1)
when substring(MyXField from 3 for 1) = 'x' then substring(MyXField from 1
for 2)
when substring(MyXField from 4 for 1) = 'x' then substring(MyXField from 1
for 3)
when substring(MyXField from 5 for 1) = 'x' then substring(MyXField from 1
for 4)
when substring(MyXField from 6 for 1) = 'x' then substring(MyXField from 1
for 5)
end,
MyPart2 = case when substring(MyXField from 1 for 1) = 'x' then
substring(MyXField from 2 for 5)
when substring(MyXField from 2 for 1) = 'x' then substring(MyXField from 3
for 4)
when substring(MyXField from 3 for 1) = 'x' then substring(MyXField from 4
for 3)
when substring(MyXField from 4 for 1) = 'x' then substring(MyXField from 5
for 2)
when substring(MyXField from 5 for 1) = 'x' then substring(MyXField from 6
for 1)
when substring(MyXField from 6 for 1) = 'x' then ''
end

With more up-to-date Firebird versions than the one I work with (Fb 2.1 or
later), I guess you could write something like:

UPDATE MyTable
SET MyPart1 = substring(MyXField from 1 for position('x' in MyXField) - 1,
MyPart2 = substring(MyXField from position('x' in MyXField) + 1 for
length(MyXField))

but I've never used this function.

HTH,
Set





[Non-text portions of this message have been removed]