truncate leading zeros

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
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

truncate leading zeros

Post by deva »

Hi I am loading data into a flat file. Data is comming in the folloing formate

its showing as 000000000008194.000 (numaric(17,3)

it should be 8194.000.

Please suggest me how to convert?
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Use trim function to remove leading zeros and define field as varchar in target
You are the creator of your destiny - Swami Vivekananda
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

anbu wrote:Use trim function to remove leading zeros and define field as varchar in target
Hi it is working fine with the following syntax

Trim(Convert(' ','',(col_name) ),"0","L")
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Please mark thread as Resolved
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

what if we have negative values. how to truncate those. this logic is not working for the negative values.

example : -00000123.21
it should be : -123.21
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

If col_name < 0 Then '-':Trim(Convert(' ','',(-1 * col_name) ),"0","L") Else Trim(Convert(' ','',(col_name) ),"0","L")
You are the creator of your destiny - Swami Vivekananda
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

what about DecimalToString() with rtype as suppress_zero?
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

priyadarshikunal wrote:what about DecimalToString() with rtype as suppress_zero?

In a column I have both negative and possitive vlues. I have to eliminate the leading zeros.

as of now I am using the below statement

If (IsNull(Col_name)=1) Then '0':Trim(Convert(' ','',(col_name) ),"0","L") Else Trim(Convert(' ','',(col_name) ),"0","L")


The above statement is working fine for possitive values. But it is not working for negative values. Can I have a statment which will work for both positive and negative values.
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

If I use the below statement leading and tailring zeros are elimination but I need 3 numbers after decimal. my input is numaric and I changed my target as varchar.

If (IsNull(col_name)=1) Then '0':Trim(Convert(' ','',(lnk_lkp_IPS_UOM2.EXTND_SALES_AMT) ),"0","B") Else if col_name < 0 Then '-':Trim(Convert(' ','',(-1 * col_name) ),"0","B") Else Trim(Convert(' ','',(col_name) ),"0","B")
example

0000231.230000 ==> 231.230
-0000231.2000000 ==> -231.200
-0000034.00000 ==> -34.000
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

svCol : Trim(Convert(' ','',(col_name) ),"0","L")
Left(svCol ,Index(svCol ,'.',1)+3)
You are the creator of your destiny - Swami Vivekananda
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

its not working , Can you please modify the above statement what I given
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Code: Select all

svCol : If (IsNull(Col_name)=1) Then '0':Trim(Convert(' ','',(col_name) ),"0","L") Else if col_name < 0 Then '-':Trim(Convert(' ','',(-1 * col_name) ),"0","L") Else Trim(Convert(' ','',(col_name) ),"0","L")

target_col : Left(svCol ,Index(svCol ,'.',1)+3)
You are the creator of your destiny - Swami Vivekananda
deva
Participant
Posts: 104
Joined: Fri Dec 29, 2006 1:54 pm

Post by deva »

Thanks for your reply,
It is working fine. But I found one more issue which the above code is not supporting

example :

input : 0000000.123
output should be 0.123

but if I apply the above code I am getting '.123'. I need '0' before decimal point.

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

Post by anbu »

Code: Select all

svCol : If (IsNull(Col_name)=1) Then '0':Trim(Convert(' ','',(col_name) ),"0","L") Else if col_name < 0 Then '-':Trim(Convert(' ','',(-1 * col_name) ),"0","L") Else Trim(Convert(' ','',(col_name) ),"0","L") 

svCol1 : If svCol[1,1] = '.' Then '0' : svCol Else svCol

target_col : Left(svCol ,Index(svCol1 ,'.',1)+3
You are the creator of your destiny - Swami Vivekananda
Post Reply