gpt4 book ai didi

SSIS 表达式无法验证

转载 作者:行者123 更新时间:2023-12-01 08:07:06 24 4
gpt4 key购买 nike

我在 SSIS 派生列组件中设置了以下表达式:

TRIM(xCOL) == "" ? (DT_STR,7,1252)xCOL : NULL(DT_STR,7,1252)

但是,这无法验证 - 我收到以下错误:

Error at PKG: For operands of the conditional operator, the data type DT_STR is supported only for input columns and cast operations. The expression "TRIM(xCOL) == "" ? (DT_STR,7,1252)xCOL : NULL(DT_STR,7,1252)" 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.

这里有什么问题?

最佳答案

Unicode - 你认为可以正常工作的所有 SSIS 事物的祸根。

TRIM(xCOL) == "" ? (DT_STR,7,1252)xCOL : NULL(DT_WSTR, 7)

默认情况下,字符串表达式的返回类型为 Unicode (DT_WSTR)。您可以通过将最后一个表达式替换为空字符串 "" 来证明这一点。查看派生列分配的类型 - 它是 DT_WSTR

TRIM(xCOL) == "" ? (DT_STR,7,1252)xCOL :  ""

然后解决方法是将 整个 表达式的结果转换为您想要的类型。 (我也认为你有一个逻辑问题,因为我假设你正在检查修剪后的字符串以确定它是否为空/零长度,然后将其转换为 NULL)。另请注意,如果您的 xCOL 字段确实为 NULL,这将会崩溃。

(DT_STR, 7, 1252)((TRIM(xCOL) == "") ? NULL(DT_WSTR, 7) :  TRIM(xCOL))

源数据

SELECT 'Hello' AS xCOL
UNION ALL SELECT ''

结果

enter image description here

关于SSIS 表达式无法验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20099331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com