select   case 
when 条件1
then (select xm,id,zjh from 表1 )
else (select xm,id,zjh from 表1 union select xm,id,zjh from 表2 )
end

解决方案 »

  1.   

    不能这么写。case when 返回的是一个值,不是一个列表或集合。
      

  2.   


    if 条件1
        select xm,id,zjh from 表1
    else
        select xm,id,zjh from 表1 
        union 
        select xm,id,zjh from 表2
      

  3.   

    select   case 
    when 条件1
    then (select xm,id,zjh from 表1 )
    else (select xm,id,zjh from 表1 union select xm,id,zjh from 表2 )
    end
    -------------------這樣寫是不行的,case when 隻能返回單一值if exists(select 1 from t where ...)select xm,id,zjh from 表1 
    else
    select xm,id,zjh from 表1 union select xm,id,zjh from 表2
      

  4.   

    if 条件1
       select xm,id,zjh from 表1
    else 
       select xm,id,zjh from 表1 
       union 
       select xm,id,zjh from 表2
      

  5.   

    if 条件1
       select xm,id,zjh from 表1
    else 
       select xm,id,zjh from 表1 
       union 
       select xm,id,zjh from 表2
      

  6.   

    if exists(select 1 from t where ...)select xm,id,zjh from 表1 
    else
    select xm,id,zjh from 表1 union select xm,id,zjh from 表2这种方法是最好的,个人认为!