--升级税务资质主表
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BASTAX_PARTY') 
insert into t_bd_taxaptitudes (fid,fnumber,fname,fstatus,fcreatorid,fmodifierid,fenable,fcreatetime,fmodifytime,fmasterid,fcreateorgid,forgid,fuseorg,fctrlstrategy,fsourcedataid,fbitindex,fsourcebitindex,fstartdate,fenddate,fcountry)
select a.fid,a.fnumber,b.fname,a.fstatus,a.fcreatorid,a.fmodifierid,a.fenable,a.fcreatetime,a.fmodifytime,a.fmasterid,a.fcreateorgid,a.forgid,a.fuserorg,a.fctrlstrategy,a.fsourcedataid,a.fbitindex,a.fsourcebitindex,a.fstartdate,a.fenddate,a.fcountry
from t_bastax_party a,t_bastax_party_l b where a.fid = b.fid and b.flocaleid = 'zh_CN' and a.fid not in (select fid from t_bd_taxaptitudes);
--升级税务资质附表
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BASTAX_PARTY_L') 
insert into t_bd_taxaptitudes_l (fpkid,fid,flocaleid,fname) select fpkid,fid,flocaleid,fname from t_bastax_party_l where fpkid not in (select fpkid from t_bd_taxaptitudes_l) ;
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BASTAX_PARTY_U') 
insert into t_bd_taxaptitudes_u (fdataid,fuseorgid) select a.fdataid,a.fuseorgid from (select fdataid,fuseorgid,fdataid+fuseorgid bastaxid from t_bastax_party_u) a where a.bastaxid not in (select fdataid+fuseorgid bdid from t_bd_taxaptitudes_u);
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_BASTAX_PARTYUSEREG') 
insert into t_bd_taxaptitudesusereg (fuseorgid,fdataid,fcreateorgid,fadminorgid,fctrlstrategy,fisassign,fassignorgid,fmasterid) 
select fuseorgid,fdataid,fcreateorgid,fadminorgid,fctrlstrategy,fisassign,fassignorgid,fmasterid from 
(select fuseorgid,fdataid,fcreateorgid,fadminorgid,fctrlstrategy,fisassign,fassignorgid,fmasterid,fuseorgid+fdataid bastaxid  from t_bastax_partyusereg ) a where a.bastaxid  not in (select fuseorgid+fdataid from t_bd_taxaptitudesusereg);