SSIS 条件表达式不处理条件转换为 NULL DT_STR

SSIS conditional expression not handling conditional cast to NULL DT_STR

我在使用 SSIS 表达式时遇到了一些问题,在派生列转换数据流任务中,我试图从字符串输入中获取 6 个字符的子字符串,如果派生列值被强制转换为 NULL不存在。这是我使用的代码,添加了换行符和缩进以提高可读性:

KeyValueLength == -2 ?
    NULL(DT_STR,6,65001) :
    (
        KeyValueLength == -1 ?
        (DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
        (DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
    )

(供参考,当KeyValueLength-2时找不到键值,当为-1时则在StringInput,任何其他数字,它位于 StringInput 的中间。此代码适用于我得到的其他键值,这些键值正在转换为 DT_I4 和 DT_DECIMAL)

单独地,以下三个表达式不会产生错误:

NULL(DT_STR,6,65001)

(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999))

(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)

但是当放在上面的嵌套条件中时,我在尝试保存 window 时收到以下错误:

For operands of the conditional operator, the data type DT_STR is supported only for input columns and cast operations. The expression "KeyValueLength == -2 ? NULL(DT_STR,6,65001) : (KeyValueLength == -1 ? (DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) : (DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength))" has a DT_STR operand that is not an input column or the result of a cast, and cannot be used with the conditional operation. To perform this operation, the operand needs to be explicitly cast with a cast operator.

我很难弄清楚这里的问题到底是什么。该错误消息表明它与条件的使用有关,但我没有看到问题。

因此,在 Microsoft 的无限智慧中,这作为 DT_STR 是空的,并且作为直接赋值是完全有效的:

NULL(DT_STR,6,65001)

但是如果你想在所有最终条件必须是同一类型的条件中分配该值,你必须这样做:

(DT_STR,6,65001)NULL(DT_STR,6,65001)

同样不适用于其他类型,其中像 NULL(DT_I4) 这样的东西无论是直接分配还是通过条件分配都是有效的。 SMH