Subject Re: [IBO] Help on stored procedures/trigger
Author Geoff Worboys
> So if I have these
>
> N00-12-001
> Z01-03-001
> A01-03-001
> A01-03-002
>
> The input of A01-03-*** from the field input mask should set
> the field to A01-03-003

You can assemble fields in triggers and procedures fairly easily. It
is pulling them apart that gets difficult (unless you have some UDFs
installed to perform substrings etc).

CHARFIELD = 'PREFIX' || INTEGERFIELD;

IB will automatically convert the integer to a string and perform the
concatenation. WARNING: If there are any calculations involved,
eg...

CHARFIELD = 'PREFIX' || (INTEGERFIELD + 1);

then IB will extend INTEGERFIELD to an int64, and will require that
CHARFIELD is large enough to handle 'PREFIX' and 18 characters of
digits (even if the result is only '2'). If you know the result will
only be a certain length you can avoid the problem by casting...

CHARFIELD = 'PREFIX' || CAST((INTEGERFIELD + 1) AS VARCHAR(5));


Your real problem is how you are going to generate the sequence number
safely in a multi-user environment. Another posting suggested
selecting the sequence number from a table - but it did not do it in a
safe manner - and it is something that is frowned upon by most
database purists.

There is an article in the IBO online help about maintaining pure
(unbroken) sequences. I dont know whether your sequence numbers must
be unbroken or not, but with only 3 digit I suspect that you would not
want too many breaks.


Is this what you were looking for?

Geoff Worboys
Telesis Computing