Removing leading '0' while decimal to varchar conversion

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
udayanguha
Premium Member
Premium Member
Posts: 37
Joined: Wed Oct 29, 2014 10:48 pm
Location: Ohio

Removing leading '0' while decimal to varchar conversion

Post by udayanguha »

Hi,
I have a decimal field of length (38,0) in my source table. In the target I want to put it as a varchar field.
I am using the TRIM function to remove leading '0's from the source field but '0's are not getting removed. Now I am using DecimalToString function which is working fine.
But I am still curious to know why trim function below is not working.

trim(field,"0","L")
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Probably there are non leading zeroes because the actual leading character is a space (" ") occupying the sign position.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
udayanguha
Premium Member
Premium Member
Posts: 37
Joined: Wed Oct 29, 2014 10:48 pm
Location: Ohio

Post by udayanguha »

I think you are right Ray, because I have a leading space for sign. So that means I first need to remove leading space and then leading '0's or rather stick to DecimalTo String with suppress zero.

Thanks Ray. I during this whole time saw this leading Space in the file and it never struck to me that '0's are not leading now. My bad!!
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

Also keep in mind that negative numbers will lead with a negative sign, not a space...
Choose a job you love, and you will never have to work a day in your life. - Confucius
weiyi_will
Participant
Posts: 10
Joined: Sun Aug 11, 2013 10:46 pm
Location: Dalian

Re: Removing leading '0' while decimal to varchar conversion

Post by weiyi_will »

I ever avoided the leading zero issue by use VarChar from reading data from DB.
Post Reply