update多表更新的2种方式
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)
from #t_RptMaterialPutDaily t1
where TermBeginQty is null
--加放回收料
update t1 set
AddCycleNO = isnull(HH_GNO,t1.CycleNO1),
AddCycleName = isnull(HH_GNO_DESC,t1.CycleName1),
AddCycleQty = m1.NUM
from #t_RptMaterialPutDaily t1
join (select k.ReceiveMO, NUM = SUM(OverQty),HH_GNO=MAX(RawNO),HH_GNO_DESC=MAX(p.FeedGrade)
from KIT_MixOver k
join ChangHong_612.dbo.MES_MaterialPacket p on k.RawNO = p.MaterialNO and k.SupplyNO = p.SupNO
where isnull(k.CheckTime,k.MixTime) between @BeginDate and @EndDate and STATE = 1
and p.ItemType in ('RecycleMaterial')
group by k.ReceiveMO
) m1 on t1.MO = m1.ReceiveMO
posted on 2015-06-05 08:57 chengjunde 阅读(448) 评论(0) 编辑 收藏 举报