Hello,
I am facing a strange problem when i try to concatinate Zero on left side of an integer its not takng that i dont know what the problem is can any one help me on this?
I have to check fo the len of the integer and if the lenght is 1 then i have to pad 2 zero's and if len is 2 then i have to pad 1 zero on the left side so that total lenght will be always 3.
I tried concatinating 0 and changed the data type from integer to varchar and nothing worked.one more thing is i tried concatinating numbers other than zero and its workng fine.
thanks in advance
unable to pad zero on left side
Moderators: chulett, rschirm, roy
-
- Charter Member
- Posts: 822
- Joined: Sat Sep 17, 2005 5:25 pm
- Location: USA
Instead of concatenating,have you tried FMT function? Something like this.
Code: Select all
FMT(in.col,"3'0'L")
I haven't failed, I've found 10,000 ways that don't work.
Thomas Alva Edison(1847-1931)
Thomas Alva Edison(1847-1931)
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Have you written a parallel version of the Fmt() function? If so, please post it.
Meanwhile, you could use something like converting to a string and overwriting the rightmost part of "000". But, in parallel jobs, integers do not have leading zeroes - only strings can.
Meanwhile, you could use something like converting to a string and overwriting the rightmost part of "000". But, in parallel jobs, integers do not have leading zeroes - only strings can.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Try this code
Make sure the definition of you target column is Varchar or Char(3) otherwise it will be converted back to integer.
Also make sure you have "fix_zero,suppress_zero") options set for DecimalToString otherwise it won't work as expected.
Code: Select all
Right('000' : DecimalToString(input.MyInteger,"fix_zero,suppress_zero"), 3)
Also make sure you have "fix_zero,suppress_zero") options set for DecimalToString otherwise it won't work as expected.
Regards,
Nick.
Nick.
Thanks a lot...
Thanks every one who responded immediately.
I choose to go with STR function and it solved my problem.
Thank you very much once again.
I choose to go with STR function and it solved my problem.
Thank you very much once again.
Try the string function .. something like this .. i have done it and worked for me
Str(string, number of times to be repeated)
i.e. STR('0', 3): FieldName woud pad three zeros to the left of FieldName
so if you write somethin like
STR('0', Length of Actual field - Len(Link.ActualField) : Actualfield
it will do the job .
actual field length is the one defined in the definition . exp char(30)
Len(Link.actualfield) will give you the length in the incoming columns
hope it helps
Str(string, number of times to be repeated)
i.e. STR('0', 3): FieldName woud pad three zeros to the left of FieldName
so if you write somethin like
STR('0', Length of Actual field - Len(Link.ActualField) : Actualfield
it will do the job .
actual field length is the one defined in the definition . exp char(30)
Len(Link.actualfield) will give you the length in the incoming columns
hope it helps
Link.ActualField is an integer as dskid said so it should be converted to a string before performing string operations on it. I know that is you tried this on a decimal field you would get warning about explicit conversion taking place, and I imagine the same is true for integers.STR('0', Length of Actual field - Len(Link.ActualField) : Actualfield
Regards,
Nick.
Nick.