将 column1(选项集)与 SSIS 中 column2(查找)中的设置值进行比较

Compare column1 (Optionset) to set value in column2 (Lookup) in SSIS

我有问题,我想根据选项集中的值在帐户中设置查找:

(DT_GUID)(industrycode == 100000009 ? (DT_STR,50,1252)"280f1c20-ad3b-eb11-c345-000d3a23cdb4" 
: (industrycode == 100000003 ? (DT_STR,50,1252)"23cc76d9-d345-eb11-a813-000d3a23cdb4" 
: (DT_STR,50,1252)"00000000-0000-0000-0000-000000000000")) 

[错误信息]

[派生列转换编辑器]

如您所见,我想在“集群”列中写入,但我正在比较“IndustryCode”是否具有选项集值。现在它向我显示此错误消息。我还尝试将其转换为 (DT_WSTR)、(DT_STR) 和 (DT_STR,50,1252)

我今天学到了两个新的 SSIS 知识。我创建了一个复制品并得到了同样的错误

Error: 0xC0049064 at Data Flow Task, Derived Column [2]: An error occurred while attempting to perform a type cast.

Error: 0xC0209029 at Data Flow Task, Derived Column [2]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Derived Column" failed because error code 0xC0049064 occurred, and the error row disposition on "Derived Column.Outputs[Derived Column Output].Columns[GuidCastError]" 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 Data Flow Task, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Derived Column" (2) failed with error code 0xC0209029 while processing input "Derived Column Input" (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.

不太重要的是,我无法创建 DT_GUID 类型的变量,即使它是有效的数据类型。

但我知道他们将 GUID 用于诸如包 ID 和执行 ID 之类的东西,所以我打开了变量 window 并检查了“显示系统范围的变量”,因为我知道它们里面有 GUID。我观察到 ExecutionInstanceGUID 的类型是 String 他们列出的值是 {0908C691-9E2A-4D42-8111-A7D98DE17BD9}。那些大括号最终成为解决问题的意外钥匙。

重写和简化您的表达式

(DT_GUID)(industrycode == 100000009 ? "{280f1c20-ad3b-eb11-c345-000d3a23cdb4}" : (industrycode == 100000003) ? "{23cc76d9-d345-eb11-a813-000d3a23cdb4}" : "{00000000-0000-0000-0000-000000000000}")

我使用查询作为我的源来测试东西

select newid() AS cluster
, D.*
FROM
(

SELECT 100000009 AS industrycode, 'case1' AS accountid
UNION ALL
SELECT 100000003 AS industrycode, 'case2' AS accountid
UNION ALL
SELECT 100000000 AS industrycode, 'case3' AS accountid
) D

你指出 accountid 是一个 guid,但为了我的测试,我想要文本以便我可以观察它。

如果您的情况比这更多,我建议您跳过派生列转换并使用查找任务。将您的查询写成

SELECT *
FROM
(
VALUES
(100000009, cast('280f1c20-ad3b-eb11-c345-000d3a23cdb4' AS uniqueidentifier))
,(100000003, cast('23cc76d9-d345-eb11-a813-000d3a23cdb44' AS uniqueidentifier))
)D(industrycode, cluster)

我会将其配置为忽略查找失败。如果您 运行 使用我的源查询,您将看到未处理全零 guid 的“其他”情况。

通过在之后添加一个派生列来解决这个问题,派生列使用像

这样的表达式
IsNull(cluster_lkp)? (DT_GUID) "{00000000-0000-0000-0000-000000000000}" : cluster_lkp