码迷,mamicode.com
首页 > 数据库 > 详细

SQL语句是以一个patch为单位编译

时间:2017-02-06 23:29:03      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:with   from   time   date   ice   处理   group by   cas   set   

如下语句如果不加go的话,当做一个批处理编译时会报错,提示没有split_count和split_amount列。加了go时可以一起执行

--3.Kit split in sale_detail: split_count,split_amount

ALTER TABLE sale_detail ADD split_count INT,split_amount float

go

--EXECUTE TIME 40 minute

UPDATE ssd SET ssd.split_count=tt.split_count,ssd.split_amount=tt.split_amount

FROM dbo.sale_detail ssd

JOIN (

SELECT a.rid,SUM(ISNULL(a.split_units,0)) AS split_count,SUM(ISNULL(a.split_rmb,0)) AS split_amount

FROM (

SELECT sd.rid, SUM(( CASE WHEN pk.count IS NULL THEN 1 ELSE pk.count END ) * sd.count) AS split_units,

SUM(CASE WHEN pk.price IS NULL THEN sd.amount ELSE pk.price * pk.count * sd.count END ) AS split_rmb

FROM sale_detail sd WITH(NOLOCK)

LEFT JOIN product p WITH(NOLOCK) ON p.product_id = sd.product_id

LEFT JOIN product_kit pk WITH(NOLOCK) ON pk.kit_id = p.product_id

AND pk.status = 0

AND sd.sale_date >= pk.start_date

AND sd.sale_date <= pk.end_date

WHERE sd.status = 0

AND p.status <> 1

AND p.ispromotion = 0

GROUP BY sd.rid

) a

GROUP BY a.rid

) tt ON ssd.rid = tt.rid

SQL语句是以一个patch为单位编译

标签:with   from   time   date   ice   处理   group by   cas   set   

原文地址:http://www.cnblogs.com/henryagg/p/6372074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!