-- 付款单收款单核心单据id、核心单据行id历史数据升级

update T_CAS_ReceivingBillEntry set  fcorebillid=fsourcebillid where (fcorebillid =' ' or fcorebillid='' or fcorebillid is null) and
  fid in(select fid from T_CAS_ReceivingBill where fsourcebilltype in('sm_salorder','conm_salcontract'));

update T_CAS_ReceivingBillEntry set  fcorebillentryid=fsourcebillentryid where (fcorebillentryid=0 or fcorebillentryid is null) and
  fid in(select fid from T_CAS_ReceivingBill where fsourcebilltype in('sm_salorder','conm_salcontract'));

update T_CAS_PaymentBillEntry set fcorebillid=fsourcebillid where (fcorebillid=0 or fcorebillid is null) and fid in(select fid from T_CAS_PaymentBill where fsourcebilltype in('pm_purorderbill'
,'conm_purcontract'));
update T_CAS_PaymentBillEntry set fcorebillentryid=fsourcebillentryid where (fcorebillentryid=0 or fcorebillentryid is null) and fid in(select fid from T_CAS_PaymentBill where fsourcebilltype in('pm_purorderbill'
,'conm_purcontract'));

update T_CAS_PaymentBillEntry set fcorebillid=(select t.fcorebillid from t_ap_applypaybillentry t where t.fentryid = fsourcebillentryid)
where (fcorebillid=0 or fcorebillid is null) and fid in(select fid from T_CAS_PaymentBill where fsourcebilltype='ap_payapply') and fsourcebillentryid!=0
and exists (select 1 from t_ap_applypaybillentry t where t.fentryid = fsourcebillentryid);

update T_CAS_PaymentBillEntry set fcorebillentryid=(select t.fcorebillentryid from t_ap_applypaybillentry t where t.fentryid = fsourcebillentryid)
where (fcorebillentryid=0 or fcorebillentryid is null) and fid in(select fid from T_CAS_PaymentBill where fsourcebilltype='ap_payapply') and fsourcebillentryid!=0
and exists (select 1 from t_ap_applypaybillentry t where t.fentryid = fsourcebillentryid);


