你的 as a2 和 where 中的a2冲突,可以改成这样:
select a1,case when len(a2)-len(@a)>0 then '001' else '000' end as aa2 (或者别的名都可以)
from aaa where a2='001'

解决方案 »

  1.   

    同意: lincanwen(Too Two To)的观点
      

  2.   

    对不起,我打错了,是:
    select a1,case when len(a2)-len(@a)>0 then '001' else '000' end as a3
    from aaa where a3='001'
    一运行就出现:列名 'a3'  无效
      

  3.   

    i agree  lincanwen(Too Two To)
      

  4.   

    你不能这样用,在Select 中定义的动态的Field不应该在where中引用,用七原来面目
      

  5.   

    你可以采用嵌套SQL语句的形式,或者
    select a1,case when len(a2)-len(@a)>0 then '001' else '000' end as a3
    from aaa where when len(a2)-len(@a)>0 then '001' else '000' end='001'
      

  6.   

    where条件中不能直接对计算列加条件.改成Having就可以了
    select a1,case when len(a2)-len(@a)>0 then '001' else '000' end as a3
    from aaa 
    having a3='001'
      

  7.   

    不好意思,错了.select a1,(case when len(a2)-len(@a)>0 then '001' else '000' end) as a3
    from aaa 
    group by a1
    having (case when len(a2)-len(@a)>0 then '001' else '000' end)='001'