update t1 set TermBeginQty =isnull((select top 1 JiaoPlusQty from WMS_RptMaterialPutDaily r where t1.MO=r.MO and (t1.MouldNO = r.MouldNO or r.MouldNO is null) and t1.MachineNO = r.MachineNO and r.BCBeginTime<@BeginDate order by r.BCBeginTime desc),0)…