Page 1 of 1

attaching 0 before an integer

Posted: Wed Dec 19, 2007 2:30 am
by arnie_nits
Hi

I have an integer field of length 11. Now I need to attach Zeros before it, in the empty spaces.
e.g if input column is 124125,then I must get 00000124125
What I have done is - IntegerToDecimal(input column) in stage variable.....then Str('0',11-input column):input column in derivation.

But I am getting 00000000 instead of say 00000124125. Someone plz help.

Regards
Arnie

Posted: Wed Dec 19, 2007 3:00 am
by rsomiset
Hi Arnie,
I think that 'Fmt' Function will help in achieving your desired output.

Regards,
Rajesh.

Posted: Wed Dec 19, 2007 3:28 am
by ArndW
An integer field does not contain leading zeroes. If you convert your integer to a string then you can use the str function as you mentioned. If you write this integer column to a text file you can also prepend leading zeroes (basically because everything going into a text file is a string).

So in order to really answer your question we need to know where this integer column is being written to.

Posted: Wed Dec 19, 2007 4:52 am
by ray.wurlod
Fmt() is a BASIC function and thus not available in parallel Transformer stage. As Arnd says, integers do not have leading zeroes; they are stored internally in binary format. Therefore, if you need leading zeroes, you also need an appropriate data type (a string of some kind). But ask yourself whether the leading zeroes are really necessary.

Posted: Wed Dec 19, 2007 9:13 am
by divine
Hi
Can you try with following:

Str('0',-11-input column)

Posted: Wed Dec 19, 2007 4:06 pm
by ray.wurlod
You've all missed the vital Len() function. Assuming the target is a string data type:

Code: Select all

Str('0',11-Len(input column)):input column 
The conversion to string for the Len() function will occur implicitly.