1. 程式人生 > >SQL0419N 十進制除法運算無效,因為結果將有一個負小數位。 SQLSTATE=42911

SQL0419N 十進制除法運算無效,因為結果將有一個負小數位。 SQLSTATE=42911

join spa lse leo case when and pan between 十進制

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‘

SQL0419N 十進制除法運算無效,因為結果將有一個負小數位。 SQLSTATE=42911