Subject SUBSTRING internal function - does not evaluate?
Author csswa
Regarding the following stored procedure, it uses DIV and MOD from
IB_UDF. SUBSTRING seems to be failing at the <POS> argument when
using variables. Tested code variations marked:

CREATE PROCEDURE SP_DEC2BASE32 (P_NUMBER INTEGER)
RETURNS (RESULT VARCHAR(7))
AS
DECLARE VARIABLE V_DIGITVALUE INTEGER;
DECLARE VARIABLE C_DIGITS CHAR(32);
BEGIN
RESULT = '';
C_DIGITS = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
WHILE (P_NUMBER > 0) DO
BEGIN
V_DIGITVALUE = UDF_MOD (P_NUMBER, 32);
P_NUMBER = UDF_DIV (P_NUMBER, 32);

*** FAILS AT <POS> ---> RESULT = SUBSTRING (C_DIGITS FROM
(V_DIGITVALUE + 1) FOR 1) || RESULT;

*** FAILS AT <POS> ---> RESULT = SUBSTRING (C_DIGITS FROM
V_DIGITVALUE FOR 1) || RESULT;

*** FAILS AT <POS> ---> RESULT = SUBSTRING (C_DIGITS FROM (1 + 1) FOR
1) || RESULT;

*** FAILS AT <POS> ---> RESULT = SUBSTRING (C_DIGITS FROM 1 + 1 FOR
1) || RESULT;

*** HOWEVER THIS IS FINE ---> RESULT = SUBSTRING (C_DIGITS FROM 1 FOR
1) || RESULT;

END
EXIT;
END

So basically it appears that if <POS> is not a simple integer value
then SUBSTRING will fail?? In the FB1 release notes it says <POS>
must evaluate to an integer which to my mind suggests it can be an
expression or variable...

Regards,
Andrew Ferguson