Page 1 of 1

converting string to decimal

Posted: Thu Aug 18, 2005 1:47 pm
by pnchowdary
Hi Guys,

Does any one know of any datastage function that converts a given string into a decimal number?

Code: Select all

For Example :-

"1943.100" is the input string that needs to be converted to decimal, so that I can apply further arithmetic operations on it.
I know of indirect techniques to achieve the same task, but I wanted to know whether there were any functions to do it directly.

Any help would be greatly appreciated.

Posted: Thu Aug 18, 2005 3:19 pm
by roy
Hi,
Check the manuals for conversion routines (Iconv/Oconv)if you must or browse your built in routines.
Bare in mind implicit conversion will occur if needed and there are also routines for arithmetic operations on character type columns like SADD and such.

IHTH,

Posted: Thu Aug 18, 2005 4:58 pm
by pnchowdary
Hi Roy,

Thank you very much for your input. However, I tried to use SADD function in the transformer and it gives an error. Therefore, I assume that it can be used only in the routines and not in the transformer. Could you please confirm whether my assumption is correct.

Posted: Fri Aug 19, 2005 1:16 am
by ArndW
DataStage will do the conversion for you automatically. If you have an input VARCHAR(10) column called MyString containing the value "1943.100" you can create an output column in a transform called MyNumber, you can do a derivation such as "In.Mystring*3.14159" and it would convert for you automatically.

Posted: Fri Aug 19, 2005 3:06 am
by Sainath.Srinivasan
In DataStage, you can do arith computations on char field as long as they hold numeric values.

You need SADD only for larger values.

Posted: Fri Aug 19, 2005 7:08 am
by pnchowdary
Thank you very much for all your responses. :D

Posted: Fri Aug 19, 2005 4:54 pm
by ray.wurlod
SADD did not give you an error. Your job would have compiled correctly with SADD(x,y) in an expression.

What you saw was the expression being red, which indicates that the expression editor's parser discovered a syntax problem. This is because the SADD function - which is a legal BASIC function - does not appear in the DSParams file, from which the expression editor's parser discovers its list of "known" functions.

If you want to use the string math functions, you can add SADD, SSUB, SMUL and SDIV into the DSParams file on the server. Sting math functions give unlimited precision.

However, type casting is automatic in server jobs, as Arnd stated, so you don't need to convert string to decimal - you can just use regular arithmetic operators.

Posted: Fri Aug 19, 2005 11:55 pm
by kumar_s
In server dont we have StringToDecimal() as like Parallel???

regards
kumar

Posted: Sat Aug 20, 2005 1:34 am
by ray.wurlod
In server we don't need StringToDecimal().

Posted: Sat Aug 20, 2005 7:20 am
by chulett
Server != Parallel. :wink:

Posted: Sun Aug 21, 2005 4:30 am
by kumar_s
ray.wurlod wrote:In server we don't need StringToDecimal().
i this ment with intention of implicit conversion :?:

Posted: Sun Aug 21, 2005 5:26 am
by roy
I think it was indeed ment as having the implicit conversion in mind for server jobs.

Posted: Sun Aug 21, 2005 8:07 am
by chulett
Agreed.

Posted: Mon Aug 22, 2005 7:08 am
by pnchowdary
Hi Ray,

You exactly hit the nail on the head. When I put in SADD(x,y) in the transformer, it was showing red color. Now, I understand why it did that and how to overcome that.

Thank you very much for clarifying it for me. :D