trim the data leading zero

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sreddy
Participant
Posts: 144
Joined: Sun Oct 21, 2007 9:13 am

trim the data leading zero

Post by sreddy »

Hi

My source data is like this.


000000001
000008753
000026843
000000084

I need the out put data as

1
8753
26843
84

i want to trim leading 0 . how can i do it.

At present i am applying the trim like this, it is not working.

Lnk1.VEND_NUM = Trim(Lnk1.VEND_NUM, "0", "F")

Please correct me.

Thanks
SReddy
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

What is the output you are getting?
You are the creator of your destiny - Swami Vivekananda
sreddy
Participant
Posts: 144
Joined: Sun Oct 21, 2007 9:13 am

Post by sreddy »

No coversion

same in the source. trim is not working.

000000001
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

Lnk1.VEND_NUM = Trim(Lnk1.VEND_NUM, "0", "L") 
L Removes leading occurrences of character

You have to use L option in Trim command
You are the creator of your destiny - Swami Vivekananda
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

... and your target, Lnk1.VEND_NUM, is what data type? Guessing... not a string.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rohithmuthyala
Participant
Posts: 57
Joined: Wed Oct 21, 2009 4:46 am
Location: India

Post by rohithmuthyala »

Convert the source data from string to decimal...automatically the zero's will be stripped off. If you still want the source data to be string then convert it back from decimal to string..!
Rohith
Kryt0n
Participant
Posts: 584
Joined: Wed Jun 22, 2005 7:28 pm

Post by Kryt0n »

rohithmuthyala wrote:Convert the source data from string to decimal...automatically the zero's will be stripped off. If you still want the source data to be string then convert it back from decimal to string..!
Have you tried that for yourself? You may just find it is the decimal causing the zeroes... and as Craig has hinted at, the OP needs to consider making his target type a String
Sairam
Participant
Posts: 42
Joined: Tue Nov 11, 2003 1:09 pm

Post by Sairam »

Kryt0n wrote:
rohithmuthyala wrote:Convert the source data from string to decimal...automatically the zero's will be stripped off. If you still want the source data to be string then convert it back from decimal to string..!
Have you tried that for yourself? You may just find it is the decimal causing the zeroes... and as Craig has hinted at, the OP needs to consider making his target type a String
Assumption:
The Incoming Field is Decimal and output is Varchar
Try this expression
DecimalToString(inCol,"suppress_zero")

If the Incoming Field is not Decimal ,try converting to Decimal [/img]
BMSK
Participant
Posts: 41
Joined: Wed Feb 06, 2008 7:00 am
Location: Bangalore

Post by BMSK »

use Abs() function


regards
BMSK
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Trim does not work because default casting to string brings the sign as first character - which will be space for positive.
datisaq
Participant
Posts: 154
Joined: Wed May 14, 2008 4:34 am

Post by datisaq »

In these scenarios you need to mention the data type(source/target).

Source: string Target: string Result: trim(col_name,'0','L') will work

Source: decimal Target: string

Result: DecimalToString(col_name,'suppress_zero') will work

Note:- trim(DecimalToString(col_name),'0','L') will not work as Sainath mentioned the problem below.


DSExperts / Sainath can you guys please be more elaborative on the above trim issue will be really great !!!
IBM Certified - Information Server 8.1
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't understand why people feel the need to come in and repeatedly speculate on what the answer might be without full disclosure of the issue from the original poster.

I don't know about anyone else but I was planning on waiting for sreddy to come back before continuing this. Didn't quite work out but... fades back into the darkness...

:wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply