update 为什么要 where exist ,不然会更新失败
如:创建临时表:create table temptable123 as select t3.fentryid fentryid,t0.FDeclarationNo FDECLARELISTNO_LT,t1.FDeclareItemNo FDECLARENO_LT,t0.FDECLARATIONDATE FDECLARATIONDATE_LT from LT_T_IEP_ImportDeclare t0
inner join LT_T_IEP_ImportDeclEntry t1 on t0.fid = t1.fid
inner join LT_T_IEP_ImportDecl_LK t2 on t1.fentryid = t2.fentryid and t2.fstablename = 'T_PUR_MRBENTRY'
inner join T_PUR_MRBENTRY t3 on t2.fsid = t3.FEntryID
inner join t_pur_mrb t4 on t3.fid = t4.fid
where t0.FDOCUMENTSTATUS = 'C'
跟新
update T_PUR_MRBENTRY
set (FDECLARELISTNO_LT,FDECLARENO_LT,FDECLARATIONDATE_LT)=
(select FDECLARELISTNO_LT,FDECLARENO_LT,FDECLARATIONDATE_LT
from temptable123
where T_PUR_MRBENTRY.fentryid = temptable123.fentryid)
where exists(select 1 from temptable123 where T_PUR_MRBENTRY.fentryid = temptable123.fentryid)
drop table temptable123
这种方式的更新的区别:
update t_bd_MaterialPurchase
set (fdefaultvendorid) =
(select fdefaultvendorid
from (select t0.fentryid fentryid, t3.fsupplierid fdefaultvendorid
from t_bd_MaterialPurchase t0
inner join T_BD_MATERIAL t1 on t0.fmaterialid = t1.fmaterialid
inner join t_BD_Supplier t2 on t1.fmasterid = t2.fmasterid
inner join t_BD_Supplier t3 on t1.fuseorgid = t3.fuseorgid
inner join T_BD_MATERIAL t4 on t4.fmasterid = t1.fmasterid
) t
where t_bd_MaterialPurchase.fentryid = t.fentryid)