Format Question

Database

Format Question

If I want to cast a decimal, say (12,2) into char so that it is right aligned, is there an easy format string to do so? Right now when I do the cast, it left aligns the number is the resulting char. I am currently using trim, left pad and retrim.

R
1 REPLY

Re: Format Question

The ANSI CAST drops leading blanks. One alternative is to use the Teradata (non-ANSI) conversion specifier. In the example below, I applied a format to the decimal value to get leading blanks and trailing zeros before coercing the result to character.

create table t3 (a decimal(12,2));
insert into t3 values (1.0);

-- The forum software software removes repeating blanks, so I'll have to demonstrate
-- with a hex dump:

.indicdata on
select (a(format 'zzzzzzzzzz.99'))(char(13)) from t3;

*** Success, Stmt# 1 ActivityCount = 1
*** Query completed. One row found. One column returned.

*** Record#1. Dump Of Data:
0000 0020 2020 2020 2020 2020 312E 3030 *. 1.00*