I want to conver varchar to integer
Moderators: chulett, rschirm, roy
I want to conver varchar to integer
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
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ray Wurlod - thanks it works great
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
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