Page 1 of 1

attaching zeros on left side.

Posted: Tue Nov 06, 2007 11:02 pm
by arnie_nits
Hi

I need to pad zeros on the left side of a varchar field. e.g:
I have a field called ID with length 6. Now if it is populated with 12,the it should come as 000012 and if 123 is populated then it should come as 000123. Please let me know if it is possible and how to implement........

Regards
Arnie.

Posted: Tue Nov 06, 2007 11:33 pm
by ArndW
Arnie, this was discussed in another current thread. The VarChar() function to use is PadChar()

Re: attaching zeros on left side.

Posted: Tue Nov 06, 2007 11:52 pm
by reddy.vinod
Hai ,
First u take two stage variables like stg1,stg2 .logic in stage varibles is

stg1=6-len(dslink.input)
stg2=str('0',stg1):dslink.input

Present i have no datastage ,i am sending this logic without checking ,try the logic if u get any problem send it to me.

Posted: Wed Nov 07, 2007 12:17 am
by JoshGeorge
ArndW, I doubt if there is any inbuild function called PadChar() available. Did you mean to say PadString()?
That function is not the best fit to this requirement (Left side / Beginning Padding).

Str() function can be used directly without stage variable specification:

Code: Select all

Str("0", 6 - Len(Input.ID)):Input.ID (Trim the input field if required)
ArndW wrote:Arnie, this was discussed in another current thread. The VarChar() function to use is PadChar() ...

Posted: Wed Nov 07, 2007 5:59 am
by arnie_nits
got it...its working....Vinod and Joshy thanks very much......

Regards
Arnie.