Error converting data type varchar to numeric.

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
Sridhar Sivakoti
Participant
Posts: 35
Joined: Tue Feb 13, 2007 5:30 am

Error converting data type varchar to numeric.

Post by Sridhar Sivakoti »

Hi,

I have designed job with source and targets are SQL Server tables. Source metadata is Varchar and Target metadata is Numeric.


I am getting below error, even I used the StringToDecimal conversion function.
APT_CombinedOperatorController,0: [DataDirect][ODBC SQL Server Driver][SQL Server]Error converting data type varchar to numeric.

Please help on this.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

You probably have non-numeric data in the input field. You can scrub the data before conversion or use the IsValid function to determine if the character data can be converted into numeric. If you look up StringToDecimal, the IsValid function is documented on the same page.

If the data is invalid, you could default it some error value. For example, if the output is supposed to be positive, convert invalid values to -1. Or filter the records out.

Hope this helps.

Brad
krishobby
Participant
Posts: 20
Joined: Sun Dec 04, 2005 3:23 pm

Re: Error converting data type varchar to numeric.

Post by krishobby »

If you have Null in the incoming rows then the StringToDecimal conversion fail throwing this error.

You can check for Nulls and empty spaces before converting

If IsNull(inputlink1) then SetNull() else If trim(inputlink1) = '' Then Setnull() else If Isvalid("decimal[10,2])", inputlink1) Then StringtoDecimal(inputlink1)
Post Reply