Archives of the TeradataForum
Message Posted: Wed, 18 Jan 2012 @ 22:51:12 GMT
Subj: | | Re: How to CAST a number without getting a decimal point. |
|
From: | | Dieter Noeth |
BOB DUELL wrote:
| This one works as well, but sorry Deiter, yours padded the result with blanks at the beginning | |
Argh, i didn't notice the ANSI CAST. Whenever i see a cast to a CHAR, i assume right aligned data :-)
Teradata style cast: first right align within the format and then apply the cast to char
SELECT (123456789. (FORMAT '-(15)9') (CHAR(16))) || '#';
(123456789.||'#')
-----------------
123456789#
SELECT (123456789. (FORMAT '-(15)9') (CHAR(29))) || '#';
(123456789.||'#')
------------------------------
123456789 #
Which leads to unexpected results when the CHAR is not large enough:
SELECT (123456789. (FORMAT '-(15)9') (CHAR(12))) || '#';
(123456789.||'#')
-----------------
12345#
ANSI style cast: first right align within the format and then trim leading blanks
SELECT CAST((123456789. (FORMAT '-(15)9')) AS CHAR(16)) || '#';
(123456789.||'#')
------------------------------
123456789 #
SELECT CAST((123456789. (FORMAT '-(15)9')) AS CHAR(29)) || '#';
(123456789.||'#')
------------------------------
123456789 #
SELECT CAST((123456789. (FORMAT '-(15)9')) AS CHAR(13)) || '#';
(123456789.||'#')
-----------------
123456789 #
Dieter
|