insert into C(系统编号,设备号,组别,地区代码) 
       select a.系统编号,a.设备号,a.组别,
              地区代码=(case when a.组别=61 then NULL
                           when right(a.组别,1)='2' then 'Store'
                           when right(a.组别,1)='1' then b.地区代码
                           else 'memory' end)
       from a left join b on a.设备号=b.单位号+b.终端号

解决方案 »

  1.   


    insert into C表 (系统编号,设备号,组别,地区代码 )
    select a.系统编号,a.设备号,a.组别,
                     case when a.组别%10=2 then 'store'
                     else case when b.地区代码 is not null then b.地区代码
                          else case when a.组别<>61 then 'memory' else null
                          end
                     end end as 地区代码
                     from A表 a left join B表 b
                      on left(a.设备号,3)=b.单位号 and right(a.设备号,3)=b.终端号