Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 18 Jan 2012 @ 22:51:12 GMT


     
  <Prev Next>   <<First <Prev
Next>
Last>>
 


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



     
  <Prev Next>   <<First <Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023