问题
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