if OBJECT_ID('tempdb..#temp1') is not null
   drop table #temp1if OBJECT_ID('tempdb..#temp2') is not null
   drop table #temp2   select khcustname, sramt, srre,srsortcol,IDENTITY(int,1,1) as id into #temp1
from vip_qyjyqkylb31
select gycustname, zcamt, zcre, zcsortcol,IDENTITY(int,1,1) as id  into #temp2
from vip_qyjyqkylb32
select khcustname, isnull(sramt,0) as sramt, srre,srsortcol,
       gycustname, isnull(zcamt,0) as zcamt, zcre, zcsortcol
from 
(
select ID from #temp1
union
select id from #temp2
)t
left join #temp1 t1
       on t.id = t1.id
left join #temp2 t2
       on t.id = t2.id