Re: Converting integers to chars
Posted in 1997
Philippe Verdy — — source: Informix-list mailing list archive (1991-1998)
>Steve Hook wrote:
>>
>> Anybody knows how to convert integers to char on a select statement?
>>
>> I need to do the following:
>>
>> select format(a) from t
>>
>> a is an integer and I need to format it as a 10 character string (padding
>> with spaces if a is less
>> than 10 characters long)
>>
>> Does such a format function exist?
CREATE PROCEDURE format(a INTEGER)
RETURNING VARCHAR(10);DEFINE result VARCHAR(10);
IF a IS NULL THEN
RETURN NULL; {or a 10-spaces constant string, as you want...}
END IF;
LET result = a;
WHILE LEN(result) < 10
LET result = ' ' || result;
END WHILE;
RETURN result;
END PROCEDURE;