【问题标题】:SSIS - Use Derived Column to Cast String to FloatSSIS - 使用派生列将字符串转换为浮点数
【发布时间】:2014-04-29 21:06:29
【问题描述】:

我在将数据从 .CSV 获取到数据类型为 FLOAT 的列中时遇到问题。我尝试直接链接它并使用数据转换任务,但是(在这两种情况下)它一直告诉我它无法转换:

Error: 0xC02020C5 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, Data Conversion [156]: Data conversion failed while converting column "Target" (22) to column "Copy of Target" (163).  The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".

我的研究使我使用了派生列转换编辑器。我找到了一些网站,指导我如何正确使用“表达”部分:

以上是我尝试将字符串(目标和废物)转换为数据类型 Float 的方式。使用编辑器时我没有收到错误消息(即它会让我单击 OK 而不会出现错误),但是,当我尝试运行包时收到错误消息:

Error: 0xC0049064 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, Map Target in correct datatype 1 1 [222]: An error occurred while attempting to perform a type cast.

Error: 0xC0209029 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, Map Target in correct datatype 1 1 [222]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "component "Map Target in correct datatype 1 1" (222)" failed because error code 0xC0049064 occurred, and the error row disposition on "output column "Target_Float" (227)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.

Error: 0xC0047022 at DC_Weekly_Cost_Target csv to FatzWklyCst_Target, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "Map Target in correct datatype 1 1" (222) failed with error code 0xC0209029 while processing input "Derived Column Input" (223). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.

这是我第一次使用派生列转换编辑器。有谁看到我做错了什么?或者,您对从 .csv 文件中获取数据到浮点数据类型列的最佳方法有什么建议吗?我感谢任何人可以给我的任何帮助。

【问题讨论】:

  • 你的目的地是什么?
  • @JeffOrris:这是 SSIS,所以目的地很疯狂。
  • 我正在尝试使用 OLE DB 目标任务将记录插入到数据库表中。

标签: ssis


【解决方案1】:

您已尝试了一种合理的方法,但数据中的某些内容导致其崩溃 - 可能是“无效”字符,例如$ 或 ,

我会用脚本任务替换派生列转换。在那里,您可以利用 .NET Framework,例如尝试... Catch、TryParse、Regex。您可以逐行调试代码以检查有错误的行。您还可以使用反射将转换代码分解为您为传递到脚本任务的每一列调用的函数。

PS:你的目的地无关紧要。

【讨论】:

  • 您仍然可以处理美元符号和逗号,而无需借助脚本任务。有字符串操作函数。您也可以先转换为 DT_CY,它需要美元符号之类的东西,然后将其转换为浮点数。
  • 我仔细检查了数据,这些字段中唯一的非数字字符是句点和负号。你对我可以做些什么来确定我的错误在哪里有什么建议吗?您能否解释一下脚本任务是如何工作的(如何将所有行传入和传出等)?感谢您的帮助!
  • 我在一个测试 CSV 文件中模拟了一些数据,以确保我的代码正常工作。当使用我的测试 CSV 文件(具有相同的数据类型)时,一切正常,因此我的派生列任务编码正确。然后,我转到我的原始 CSV 文件并一次添加一列。 2 个浮点列中的第一个工作正常(即使不使用派生列任务),但第二个没有。我看了看,文件的最后一行显示 , , , , Page 1 of 1。当我(手动)删除该行时,它起作用了。现在我只需要以编程方式执行此操作。谢谢你的帮助!!
  • 当您将脚本任务添加到数据流时,它会生成代码的外壳(VB 或 C# - 您的选择)并包括显示与变量和列交互的语法的 cmets。在脚本任务的属性中,您可以定义它可以访问哪些变量和列。
猜你喜欢
  • 2020-04-02
  • 2021-06-28
  • 2021-11-24
  • 2011-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-25
  • 1970-01-01
相关资源
最近更新 更多