select proxyid,hisid,proxyid+hisid as zhcx into #sale_proxy from zy_yp1_proxysalesdetail group by proxyid,hisid
insert into zy_yp1_proxy_his(proxyid,hisid) select proxyid,hisid from #sale_proxy where proxyid+hisid not in(select proxyid+hisid from zy_yp1_proxy_his)
select * from zy_yp1_proxy_his where hisname is null
update zy_yp1_proxy_his set hisname=left(b.hisname,30) from zy_yp1_proxy_his a,zy_yp1_his b where a.hisid=b.hisid
drop table #sale_proxy