select table1.*,(case when table2.zlbm is null then 'f' else 't' end ) as yn 
from table1 left join table2 on table1.zlbm=table2.zlbm

解决方案 »

  1.   

    select * ,case when (select top 1 zlbm from table2 where zlbm=table1.zlbm) is not null then 't' else 'f' end as yn
    from table1
      

  2.   

    select table1.*, 'T' as YN from table1 where exists (select 1 from table2 where table1.zlbm=table2.zlbm)
    union
    select table1.*, 'F' as YN from table1 where not exists (select 1 from table2 where table1.zlbm=table2.zlbm)