You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSIS派生列条件表达式未返回预期结果求助

解决SSIS派生列航向判断的表达式问题

嘿,我一眼就看出你这个表达式的问题啦——你用了字符串类型来比较航向数值,这会导致逻辑完全出错!

问题根源

航向值(比如315、45)本质是数值,但你把它们当作字符串来比较。字符串比较是按字符逐个对比的:比如"315"和"45",第一个字符'3'比'4'小,所以字符串层面"315" < "45",这就导致你第一个判断Step1_Emc_stg_Heading >= "315" && Step1_Emc_stg_Heading <= "45"永远不可能成立,因为没有字符串能同时满足既大于等于"315"又小于等于"45"。

另外,315到45这个航向区间是跨0度的(从西北到东北),数值上315比45大,所以不能用&&,得用||(或)来拆分条件。

修正后的表达式

先把航向字段转换成数值类型(比如整数DT_I4),再用数值逻辑判断:

(DT_STR,255,1252)
(
    ((DT_I4)Step1_Emc_stg_Heading >= 315 || (DT_I4)Step1_Emc_stg_Heading <= 45) ? "Northbound" :
    ((DT_I4)Step1_Emc_stg_Heading >= 46 && (DT_I4)Step1_Emc_stg_Heading <= 135) ? "Eastbound" :
    ((DT_I4)Step1_Emc_stg_Heading >= 136 && (DT_I4)Step1_Emc_stg_Heading <= 225) ? "Southbound" :
    ((DT_I4)Step1_Emc_stg_Heading >= 226 && (DT_I4)Step1_Emc_stg_Heading <= 314) ? "Westbound" :
    "Nobound"
)

额外提醒

如果你的Step1_Emc_stg_Heading字段可能包含非数值内容(比如空值、字母),建议先加个数值校验,避免转换出错:

(DT_STR,255,1252)
(
    ISNUMERIC(Step1_Emc_stg_Heading) == 0 ? "Invalid Heading" :
    ((DT_I4)Step1_Emc_stg_Heading >= 315 || (DT_I4)Step1_Emc_stg_Heading <= 45) ? "Northbound" :
    ((DT_I4)Step1_Emc_stg_Heading >= 46 && (DT_I4)Step1_Emc_stg_Heading <= 135) ? "Eastbound" :
    ((DT_I4)Step1_Emc_stg_Heading >= 136 && (DT_I4)Step1_Emc_stg_Heading <= 225) ? "Southbound" :
    ((DT_I4)Step1_Emc_stg_Heading >= 226 && (DT_I4)Step1_Emc_stg_Heading <= 314) ? "Westbound" :
    "Nobound"
)

内容的提问来源于stack exchange,提问作者manoj yadla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:03:32