.net

.net

博客园 首页 新随笔 联系 订阅 管理

select case when sum(qty_sold*u.um03/u.um08) <> 0 then
decimal(coalesce(sum(d.amt_sold_with_tax)/sum(qty_sold*u.um03/u.um08),0), 18, 2)
else 0 end as value
from item_saleorg_day_2019 d
left join rpt_item_um u on d.item_id = u.item_id
left join dim_item i on d.item_id = i.item_id
where d.date1 between '20190101' and '20190106'

出现下面的错误:

 SQL0419N  十进制除法运算无效,因为结果将有一个负小数位。  SQLSTATE=42911

 

SQL改为下面就可以了:

select case when sum(qty_sold*u.um03/u.um08) <> 0 then
decimal(coalesce(sum(d.amt_sold_with_tax)/dec(sum(qty_sold*u.um03/u.um08),30,2),0), 18, 2)
else 0 end as value
from item_saleorg_day_2019 d
left join rpt_item_um u on d.item_id = u.item_id
left join dim_item i on d.item_id = i.item_id
where d.date1 between '20190101' and '20190106'

posted on 2019-01-07 03:03  航宇  阅读(1989)  评论(0编辑  收藏  举报