更新订单表里面的快递运费

    主要是针对那些一张订单有几条记录的信息,先前寸的EMSGold都是总的,现在想把它更新为按其礼品金币值占比分配快递费用,具体脚本如下:

select ID,MAX(SEQ_NO) as MA,COUNT(ID) as T
into #temp001
from dbo.Fact_Order_Gift
where EMSPayGold >0
group by ID having COUNT(ID)>=2 --找出有多条记录的信息

--#temp002主要是为了后面算最大SEQ_NO的快递费用做铺垫

select ID,SUM(round(EMSPayGold*((GiftGold*GiftNum)*1.0/PayGold),0)) as PartGold
into #temp002
from dbo.Fact_Order_Gift
where ID in (select ID from #temp001)
and SEQ_NO not in (select MA from #temp001)
group by ID

update dbo.Fact_Order_Gift
set EMSPayGold=case
when a.SEQ_NO<b.MA then Round(a.EMSPayGold*((a.GiftGold*a.GiftNum)*1.0/a.PayGold),0)
when a.SEQ_NO=b.MA then a.EMSPayGold-c.PartGold end
from dbo.Fact_Order_Gift A,#temp001 B,#temp002 c
where a.ID=b.ID and a.ID=c.ID

脚本本身很简单,只是做个记录,以后说不定还要用。

posted @ 2011-12-30 16:37  诺哥的传奇  阅读(298)  评论(0编辑  收藏  举报