【问题标题】:Error messages when I execute SQL Query in the Where Statement在 Where 语句中执行 SQL 查询时出现错误消息
【发布时间】:2020-06-25 15:29:00
【问题描述】:

我使用 SQL Server Management Studio 创建了一个 SQL 查询, 但是,我在 Where 语句中遇到了错误。

这里是WHERE子句的SQL代码:

   where 
       (case when 'All' in (select Items from CDB.dbo.Split (@a,','))
        then  innt.code **IS** NOT NULL
        else  innt.code in (select Items from CDB.dbo.Split (@a,',')) end) and

我收到以下错误消息:

消息 156,第 15 级,状态 1,第 90 行
关键字“IS”附近的语法不正确。

消息 156,第 15 级,状态 1,第 92 行
关键字“and”附近的语法不正确。

你们能帮我解决这个问题吗?

【问题讨论】:

    标签: sql sql-server


    【解决方案1】:

    布尔值不是 SQL Server 中的一种类型。所以case 不能返回布尔表达式。

    所以,只需使用常规比较

    where ('All' in (select Items from CDB.dbo.Split(@a, ',') and innt.code IS NOT NULL) or
          (innt.code in (select Items from CDB.dbo.Split(@a, ',') )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2021-06-27
      • 2021-08-03
      • 1970-01-01
      相关资源
      最近更新 更多