'How to return value with two decimal places
I am having trouble returning the result of a calculation with two decimal places, my query runs fine in my client but my presentation software seems to have a problem with CAST, is there another way/function I could use to accomplish this?
CASE
WHEN HHICWCD = 'Y' THEN CAST((HHIEXCW * HHIPRCN) AS NUMERIC(5,2))
WHEN HHICWCD = 'N' THEN CAST((HHIQYSA * HHIPRCN) AS NUMERIC(5,2))
ELSE 0.00
END AS "Extended Price",
Solution 1:[1]
I changed DECIMAL(5,2) to DECIMAL(7,2) and it now works, thank you all for your help, learning every day!
Solution 2:[2]
CAST(CASE HHICWCD
WHEN 'Y' THEN HHIEXCW * HHIPRCN
WHEN 'N' THEN HHIQYSA * HHIPRCN
ELSE 0
END AS DECIMAL(5,2)) AS "Extended Price",
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dan B. |
| Solution 2 | SQLpro |
