select  bjflmc2  from bjfl2  where bjflmc2 not in (select  bjflmc2  from  bjfl3表  )
union all
select  bjflmc2  from  bjfl3表 

解决方案 »

  1.   


    create table bjfl2(bjflmc2 nvarchar(20),bjflmc1 nvarchar(20))
    insert bjfl2
    select 'A巡更棒','全部' union all    
    select 'B通讯底座','全部' union all       
    select 'C信息钮','全部' union all     
    select 'D传输线','全部' union all       
    select 'E皮套','全部' union all     
    select 'F配件','全部' union all    
    select '充电器','全部' union all  
    select '访客系统','全部' union all  
    select '钥匙管理柜','全部' create table bjfl3(bjflmc3 nvarchar(20),bjflmc2 nvarchar(20))
    insert bjfl3
    select '巡更棒接触式A1','A巡更棒' union all  
    select '巡更棒感应式A2','A巡更棒' union all  
    select '通讯座接触式B1','B通讯底座' union all  
    select '通讯座感应式B2','B通讯底座' union all  
    select '信息钮接触式C1','C信息钮' union all  
    select '信息钮感应式C2','C信息钮' 
    select case when b.bjflmc2 IS null then a.bjflmc2 
    else b.bjflmc3
    end
    from bjfl2 a
    left join bjfl3 b
    on a.bjflmc2=b.bjflmc2
    order by b.bjflmc2/*
    D传输线
    E皮套
    F配件
    充电器
    访客系统
    钥匙管理柜
    巡更棒接触式A1
    巡更棒感应式A2
    通讯座接触式B1
    通讯座感应式B2
    信息钮接触式C1
    信息钮感应式C2
    */