【问题标题】:Convert Nested IF Excel Statement to SQL将嵌套的 IF Excel 语句转换为 SQL
【发布时间】:2021-08-18 07:34:25
【问题描述】:

有人可以帮我将 Excel 中的嵌套 IF 公式转换为 SQL 中的 CASE 语句(或任何更有效的语句)吗?:

=IF(B11="",IF(OR(R11="STORY.COM",R11="EXPERIENCE"),FALSE,IF(AE11="Yes",TRUE,IF(AE11="Unknown",IF(D11="",IF(E11="",FALSE,E11),D11),FALSE))),B11)

提前谢谢你

【问题讨论】:

  • 请标记您的 dbms。
  • 请向我们展示您到目前为止所做的尝试。
  • 如果不使用为此目的创建的一些插件,您不能直接在excel中编写sql。另一种选择是使用 VBA 和 OLEDB 对象来查询您的 excel 数据,但如果您不习惯使用它,那么最终的公式可能比您要求的更容易。

标签: sql sql-server excel tsql


【解决方案1】:

如果您从左到右滚动并输入case.. when.. then.. else..end,您将得到以下结果:

case when B11 = ''
        then case when R11 = 'STORY.COM' or R11 = 'EXPERIENCE'
                then 'False'
                    else
                        case when AE11='Yes'
                            then 'True'
                        else
                            case when AE11='Unknown'
                                then case when D11=''
                                        then case when E11=''
                                            then 'False'
                                        else E11 end
                                else D11 end
                            else
                                'False' end end end
                else
                    B11 end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多