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


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'


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM