SSIS如何在来源多于2个小数的情况下将字符串(DT_STR)转换为货币(DT_CY) [英] SSIS how to convert string (DT_STR) to money (DT_CY) when source has more than 2 decimals

查看:170
本文介绍了SSIS如何在来源多于2个小数的情况下将字符串(DT_STR)转换为货币(DT_CY)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源平面文件,其值如24.209991,但是它们需要以money类型加载到SQL Server。在DTS(我要从中转换)中,该值为24.21。如何在SSIS中转换该字段?

I have a source flat file with values such as 24.209991, but they need to load to SQL Server as type money. In the DTS (which I am converting from), that value comes across as 24.21. How do I convert that field in SSIS?

现在,我只是将类型从DT_STR更改为DT_CY,这会导致运行错误数据转换失败。列 Col003的数据转换返回状态值2和状态文本由于潜在的数据丢失,无法转换该值。。'

Right now, I am just changing the type from DT_STR to DT_CY, and it gives a run error of 'Data conversion failed. The data conversion for column "Col003" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".'

我使用数据转换任务?然后呢?

Do I use a Data Conversion task? And then what?

我也尝试将源输出列设置为DT_NUMERIC,然后将其转换为DT_CY,结果相同。

I've also tried setting the source output column to DT_NUMERIC, and then convert that to DT_CY, with the same result.

我也尝试使用派生列,将DT_STR字段Col003强制转换为(DT_NUMERIC,10,2)Col003,然后将其强制转换为(DT_CY)Col003_Numeric。

I've also tried using Derived Columns, casting the DT_STR field Col003 to (DT_NUMERIC,10,2)Col003 and then casting that to (DT_CY)Col003_Numeric. That's getting a cast error.

推荐答案

平面文件默认所有字段均为DT_STR。在编辑连接时使用高级选项,以使数字字段为浮点型(DT_R4)。然后,在平面文件源的高级编辑中(在数据流选项卡上),将输出列设置为money(DT_CY)。

The flat file defaults to all fields being DT_STR. Use the Advanced option on editing the connection to have the numeric field as float (DT_R4). Then, in the advanced editing of the Flat File Source (on the Data Flow tab), set that output column to money (DT_CY).

然后,该字段将转换无需任何其他转化。问题是将源文件定义保留为DT_STR。

Then, the field will convert without any additional conversions. The issue was leaving the source file definition as DT_STR.

这篇关于SSIS如何在来源多于2个小数的情况下将字符串(DT_STR)转换为货币(DT_CY)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆