Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with converting DEC to CHAR

Status
Not open for further replies.

tbtcust

Programmer
Oct 26, 2004
214
US
Hi all.

SELECT CHAR(aDecColumn) is adding leading zeros to my result set, e.g.,

5.000 is 0000000005.000

How can I suppress the leading zeros?

env
db2 v 8.14

Thanks in advance for any help.
 
When it's a whole numer, just cast it to INT. The CHAR(INT)) does not generate leading zeros. If it is not a whole number then you get ugly code like this:
Code:
select case when TOT_M < 9   then substr(char(TOT_M),09,03)
            when TOT_M < 99  then substr(char(TOT_M),08,04)
            when TOT_M < 999 then substr(char(TOT_M),07,05)
            else                         char(TOT_M)  
        end as result
but it works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top