尝试模拟CASE表达式时,SSIS包中的“数据流任务错误”

时间:2019-08-31 09:27:31

标签: sql-server ssis

我搜索了此错误,并找到了该问题的一些链接,但我找不到我的错误是什么 有我的情况:

在使用SSIS包传输数据之前,我需要在结果中添加一个case表达式

,CASE
        WHEN [REFERENCE]  = 33 THEN 'Planned Purchase Orders'
        WHEN [REFERENCE]  = 34 THEN 'Planned Transfer' 
   END AS [REFERENCENAME]

由于某种原因,我无法在源代码上执行此操作, 但是,我尝试使用以下语法SSIS处理([REFERENCE] == "33" ) ? "Planned Purchase Orders": ( [REFERENCE] )中的派生列 但是我遇到了这个错误:

    TITLE: Microsoft Visual Studio
------------------------------

Error at Data Flow Task [Derived Column [151]]: The data types "DT_I4" and "DT_WSTR" are incompatible for binary operator "==". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.

Error at Data Flow Task [Derived Column [151]]: Attempt to set the result type of binary operation "REFERENCE == "33"" failed with error code 0xC0047080.

Error at Data Flow Task [Derived Column [151]]: Computing the expression "([REFERENCE] == "33"  ) ? "Planned Purchase Orders": ( [REFERENCE] )" failed with error code 0xC0047084. The expression may have errors, such as divide by zero, that cannot be detected at parse time, or there may be an out-of-memory error.

Error at Data Flow Task [Derived Column [151]]: The expression "([REFERENCE] == "33"  ) ? "Planned Purchase Orders": ( [REFERENCE] )" on "Derived Column.Outputs[Derived Column Output].Columns[Derived Column 1]" is not valid.

Error at Data Flow Task [Derived Column [151]]: Failed to set property "Expression" on "Derived Column.Outputs[Derived Column Output].Columns[Derived Column 1]".



------------------------------
ADDITIONAL INFORMATION:

Exception from HRESULT: 0xC0204006 (Microsoft.SqlServer.DTSPipelineWrap)

------------------------------
BUTTONS:

OK
------------------------------

enter image description here

1 个答案:

答案 0 :(得分:2)

这有点猜测,但是我认为Reference是一个整数吗?如果是这样,您需要执行以下操作并将该值转换为“ else”中的WSTR:

([REFERENCE] == 33 ) ? "Planned Purchase Orders": ( (DT_WSTR,30) [REFERENCE] )

SSIS不会隐式转换值;您必须非常明确(它甚至不会隐式地为STR投射WSTR)。结果,您必须指定使用DT_WSTR函数将I4转换为WSTR。