【问题标题】:witing a case statement in SSIS在 SSIS 中编写案例语句
【发布时间】:2019-06-07 14:40:00
【问题描述】:

我正在设置一个包以将 Excel 电子表格导入 SQL 数据库。电子表格中有一个列,我想在其中挑选关键字,然后将它们放入新列中。在 SQL 中,它就像一个基本的 case 语句

case when column_A like '%Norwich%' then 'Norwich'
    when column_A like '%Ipswich%' then 'Ipswich'
    when column_A like '%Cambridge%' then 'Cambridge'
    else 'NA'
end as NewColumn

我已经尝试了以下方法,但我猜它不能正常工作,因为我现在有通配符

[Report Title] == "Norwich" ? "Norwich" : [Report Title] == "Ipswich" ? "Ipswich" : [Report Title] == "Cambridge" ? "Cambridge" : "NA"

例子:

Report Title                      NewColumn

Norwich is in Norfolk             Norwich
Cambridge is in Cambridgeshire    Cambridge
Suffolk is home to Ipswich        Ipswich

【问题讨论】:

标签: sql sql-server ssis expression etl


【解决方案1】:

您必须使用带有嵌套条件运算符的FINDSTRING() 函数来实现:

FINDSTRING([Report Title],"Norwich",1) > 0 ? "Norwich" : (
FINDSTRING([Report Title],"Ipswich",1) > 0 ? "Ipswich" : (
FINDSTRING([Report Title],"Cambridge",1) > 0 ? "Cambridge" : "NA"))

参考文献

【讨论】:

    猜你喜欢
    • 2023-01-26
    • 2021-11-17
    • 2018-07-14
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多