【问题标题】:Invalid Column name for where condition valuewhere 条件值的列名无效
【发布时间】:2022-01-06 02:18:38
【问题描述】:

这是我的 SQL 语句:

Set @xyz = @xyz + isnull(@Where, @And) + ' ' + @ColName + 
           ' in (select max(cid) from demo where status = RELEASE group by cid)' 

消息 207,第 16 级,状态 1,第 1 行
列名“RELEASE”无效。

select max(cid) 
from demo 
where status = RELEASE 
group by cid

独立执行时工作正常。

但是当它在子查询中追加时会导致无效的列名 RELEASE 错误

【问题讨论】:

    标签: sql subquery where-clause


    【解决方案1】:

    您应该在 'RELEASE' 中使用 status = RELEASE 值。

    Set @xyz = @xyz + isnull(@Where, @And) + ' ' + @ColName + 
           ' in (select max(cid) from demo where status = \'RELEASE\' group by cid)'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-02
      • 2019-07-12
      • 2022-11-30
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多