ANKUR JAIN

July 2, 2007

DB2 decimal to varchar conversion issue : leading zeroes

Recently, I came across this problem, someone faced while casting a decimal datatype to varchar data type in DB2.

Here’s the link to the whole thread :

db2– Decimal to Varchar without leading zeros

So, the idea is to replace the 0’s with spaces and convert them back to 0 with second replace. I’ve already explained the reason for this double-do for both replace and rtrim/ltrim functions instead of a single trim, strip functions.

Filed under: Wired-News — Ankur Jain @ 7:16 am

1 Comment »

  1. Hi, try this:

    cast(rtrim(char(int())) || ‘.’ || substr(char(),locate(’.', char())+1,2) as varchar(25))

    Comment by ekSi — November 7, 2007 @ 8:51 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress