无法使用 SSIS 将 DT_NTEXT 转换为 NUMCERIC

Can't convert DT_NTEXT to NUMCERIC using SSIS

我们通过 Power Query 从网络加载 CSV。在其他列中,有三个数据类型为 DT_NTEXT 的货币列作为输出列。我已经尝试使用数据转换任务作为将列转换为 DT_WSTR(4000) 的第一件事,然后在具有以下表达式的以下派生列任务中将它们转换为数字(17,5):

TRIM(price_conv) == "" ? NULL(DT_NUMERIC,17,5) : ((DT_NUMERIC,17,5)TRIM(price_conv))

不幸的是,这仍然失败。

错误信息:

[Derived column [2]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Derived column" failed because error code 0xC0049063 occurred, and the error row disposition on "Derived column.Output[Output of the Derived column].column[price_derived]" 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.

[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "erived column" (2) failed with error code 0xC0209029 while processing input "Inputof the derived column" (3). 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.

PS:错误消息部分翻译自德语。

我也试过在Power Query源码的高级编辑器中设置DT_WSTR,同样失败

有人知道吗?

问题是没有从ntext到numeric的隐式或显式转换,参考:https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver15

trim 首先会失败,所以您可能需要做的,正如 billinkc 所建议的那样,是一个双重转换,到 wstr,trim,然后到数字:

(DT_NUMERIC,17,5)TRIM((DT_WSTR,20)(price_conv))

我不得不对分隔符(. 和 ,)使用替换函数,然后它起作用了。

#1 使用数据转换任务或派生列任务

转换为DT_WSTR

#2注意分隔符,必要时用replace函数替换

示例:

TRIM(origprice_conv) == "" ? NULL(DT_NUMERIC,17,5) : ((DT_NUMERIC,17,5)REPLACE(TRIM(origprice_conv),".",",")) 

origprice_conv 已经转换为 DT_WSTR.

可惜SSIS这里没有给出有意义的错误信息

我的问题有两方面,但数据查看器帮助识别了问题。首先是我可以为 origprice_conv 设置空白值,而默认转换不起作用。我通过将 null 转换为正确的 DT_NUMERIC 规范来解决这个问题。第二个问题是源数据在数据中使用了美式小数位。在德国,转换预期字符串为“123,45”而不是“123.45”。国际化说明,句点是德国的千位分隔符。