Removing Leading Zeroes

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
inter5566
Premium Member
Premium Member
Posts: 57
Joined: Tue Jun 10, 2003 1:51 pm
Location: US - Midwest

Post by inter5566 »

Check the help Docs. for trim

Steve
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

rjackson

Add zero if it is always a number.

trim(fieldname,"0","L") - will remove all leading zeros.

oconv(iconv(fieldname,"MD0"),"MD0") - will move decimal place zero places and convert to a number.

Need more.

Kim.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

rjackson

oconv(iconv(fieldname,"MD0"),"MD0") will only work if you have no decimal places because it will trucate everything after the decimal place.

Almost everything in DataStage is a string.

X = 123 if X = "00123" + 0.

That is always the easiest way. oconv() and iconv() were designed originally to clean up this kind of problem but they are relatively slow because they can do so many things. You can always trap errors like this:

if num(X) then X + 0 else X

Kim.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Kim's answer covers almost everything I wanted to say.
You may need to consider "" (the zero length string) and NULL (the unknown value).
NULL isn't a problem, since if the result of the condition test is NULL in an IF statement, the ELSE path is always taken (the rationale is that we can't assert that an unknown value is true).
However, "" is considered to be numeric in a numeric context, so that the expression would replace "" with 0. If you know you're never going to get "" in your data, you don't need to worry about this. Otherwise modify the expression as follows.
If Len(x) And Num(x) Then x + 0 Else x

Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
Post Reply