Money data type is overflowed

Viewed 593

I am working on SSIS 2008. My task is to get the stats from a table in OLE BD and save it in a flat file. I am using two fields in a table saved in OLE DB the fields are in NVARCHAR data type. Amount and Currency are the two fields. I wanted the SUM of Amount, so tried using Decimal and Numeric to cast but it didnt work so used Money and it worked.

My Query is:

select sum(cast(PAID_AMOUNT as money)) as Amount, CUR as AmountCurrency, COUNT(*) as Records 
from Raw_table group by CUR order by 2

I am using a OLE DB source editor - SQl command option to query the statement. Clicking on the preview button displays the result without any error.

But when I execute the task i am getting an error:

[Inv Stats [1]] Error: There was an error with output column "Amount" (17) on output "OLE DB Source Output" (11). The column status returned was: "Conversion failed because the data value overflowed the specified type.".

so I captured the error causing row in a flat file by redirecting the error. and the file captured :

Amount,AmountCurrency,Records,ErrorCode,ErrorColumn
3073904391,JPY,9806,-1071607691,17

I am new to SSIS and have poor knowledge on data types. Please help. Apologies if my description is not clear as this is my first post.

2 Answers

The value coming from your SQL query, of type money, with a value of 3073904391, will overflow a column of type [DT_I4]. I'm not sure how you've ended up with [DT_I4] using that query in an OLE DB Source (when I set this up from scratch it defaults to currency [DT_CY]), but I recommend changing the data type in Advanced Editor > Input and Output Properties > Output Columns to currency [DT_CY].

According to this MSDN article, if the SUM() function in sql server is applied on Money data type it returns a value of type Money

The related SSIS data type for Money is DT_CY, so you have to make sure that the Amount column data type is DT_CY, Just Right click on the OLEDB Source and go to the advanced editor to check this.

OLE DB Source --> right click "Advanced Editor" --> Input/Output Properties --> OLE DB Source Output --> expand "Output Columns" --> Click on Amount column and change the data type from the properties to DT_CY

If you want to learn more about SSIS data types and the related SQL server data type just follow the links below:

Related