无效的列名,在选择语句创建的列上 [英] Invalid column name, on select-statement created columns

查看:18
本文介绍了无效的列名,在选择语句创建的列上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将我的问题简化为以下选择语句.

I have simplified my problem to the following select statement.

select 
   u.UserId,
   aVariable = cast((case when exists(select * from TblUser u where u.Disabled=1) then 1 else 0 end) as bit), 
from TblUser u
where aVariable = 1

aVariable 不是表的列,而只是在此 select 语句中获取值的列.

aVariable is not a column of a table, but just a column that gets a value in this select statement.

有没有办法在不获取列名无效 aVariable 错误?

Is there a way to do the above without getting the Invalid column name aVariable error?

推荐答案

select q.* from (
select 
   u.UserId,
   cast((case when exists(select * from TblUser u where u.Disabled=1) then 1 else 0 end) as bit) as aVar, 
from TblUser u
)q 
where q.aVar = 1

这篇关于无效的列名,在选择语句创建的列上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆