How to supress leading Zeros

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Shree0410
Participant
Posts: 70
Joined: Tue Nov 29, 2005 7:25 pm

How to supress leading Zeros

Post by Shree0410 »

I have a column of lenth 10 which could possible have leading zeroes.

How can I supress the leading zeros. I worked this out by checked byte by byte accross the 10 bytes, but us there is a masking function that I can use?

Thanks for the help
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You could define it as a numeric datatype, which would automagically do that for you, or you could check out the FMT function.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Multiply it by 1 :lol:
An arithmatic manipulation on a character forces it to become an integer (implicit conversion).
Another way :wink:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

If you try math on a NULL value, you'll get an Abnormal Termination. Consider any of these options:

Code: Select all

If ISNULL(link.column) OR NOT(NUM(link.column)) Then 0 Else link.column * 1

Code: Select all

If ISNULL(link.column) OR NOT(NUM(link.column)) Then 0 Else link.column + 0
To enforce a set number of decimal places with rounding:

Code: Select all

If ISNULL(link.column) OR NOT(NUM(link.column)) Then 0 Else OCONV(link.column, "MDxy")
where x is the number of decimals remaining after the y decimal shift
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Thanks Ken for the input, completely overlooked that :roll:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
cconley
Premium Member
Premium Member
Posts: 4
Joined: Fri Nov 12, 2004 12:21 am
Contact:

Post by cconley »

Using the Trim function with the "L" option will also trim leading zeros: Trim(field,'0','L')
michaeld
Premium Member
Premium Member
Posts: 88
Joined: Tue Apr 04, 2006 8:42 am
Location: Toronto, Canada

Post by michaeld »

This will do it:

DecimalToString(ColumnName),"fix_zero,suppress_zero")
Mike
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not in a server job, it won't!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply