I want to conver varchar to integer

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
ranga1970
Participant
Posts: 141
Joined: Thu Nov 04, 2004 3:29 pm
Location: Hyderabad

I want to conver varchar to integer

Post by ranga1970 »

My Source is varchar target is Decimal, i am using CONVERT(Decimal(10), X.GROUP_NO) where is x is source but the process is going on for infinite time, could some one help? suggestions???
RRCHINTALA
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Please post question in the correct category like Ascential DataStage Server Edition.
Mamu Kim
ririr
Participant
Posts: 84
Joined: Sun Apr 04, 2004 8:59 pm

Post by ririr »

Please create a routine (ToInteger) using the following code.. I am using it to convert the strings such as "001234" to integer, and it works great..

If Num(Arg1) = 1 and IsNull(Arg1) = 0 Then
d = Field(Arg1, ".", 2)

If IsNull(d) = 1 Then
Ans = Int(Arg1)
End Else
If d[1,1] >= 5 Then
Ans = Int(Arg1) + 1
End Else
Ans = Int(Arg1)
End
End

End Else
If Alpha(Arg1) = 1 Then
Ans = 0
End Else
Ans = @NULL
End
End
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

This may be more efficient. Both the Fmt() function and the Iconv()/Oconv() function can perform rounding/truncation. Rounding is the default.

Code: Select all

If Num(Arg1)
Then
    Ans = Iconv(Arg1, "MD0")
End
Else
    Ans = (If Alpha(Arg1) Then 0 Else @NULL)
End
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ranga1970
Participant
Posts: 141
Joined: Thu Nov 04, 2004 3:29 pm
Location: Hyderabad

Ray Wurlod - thanks it works great

Post by ranga1970 »

ririr,
thanks it works but many more thanks for Ray Wurlod who gave simpler code based on your logic, thanks to both you guys for your help
ranga
RRCHINTALA
Post Reply