Integer and not DECIMAL

时光总嘲笑我的痴心妄想 提交于 2019-12-11 07:49:50

问题


Why I am getting Integer in this output (I am expecting DECIMAL) Database flavor is Teradata What am I doing wrong?

CASE WHEN sub_e.LSD IS NOT NULL  THEN CAST(baba.amt AS DECIMAL(10,2))  
ELSE 0
END
-
(
SUM(
     CASE 

        WHEN sub_e.LSD IS NOT NULL          
        THEN ch.actv_amt  * (1 + ch.tax_percent_rate/100) 

     ELSE 0

     END
    )
)
 +
 CASE WHEN  
                sub_e.LSD IS NOT NULL THEN COALESCE(sub_e.PWC, 0)
 ELSE 0
 END                

  AS ODTS,

回答1:


If TAX_RATE_PERCENT is not defined as a DECIMAL of sufficient precision then your calculation of (1 + TAX_RATE_PERCENT/100) will be incorrect.

SELECT 6/100; -- 0 (zero - Integer division)

SELECT 6.0/100; -- 0.1 (rounding rules based on precision of numerator)

SELECT 6.00/100; -- 0.06 (expected answer)

SELECT CAST(6 AS DECIMAL(2,1))/100; -- 0.1 (rounding rules based on precision of numerator)

SELECT CAST(6 AS DECIMAL(3,2))/100; -- 0.06 (expected answer)

For more details on DECIMAL data type behavior in Teradata see Dnoeth's explanation here.




回答2:


the problem was in the definition of a solumn inside the table where the result of the query above is doing INSERT



来源:https://stackoverflow.com/questions/17404617/integer-and-not-decimal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!