I have a varchar field AMOUNT
in DB2.
Possible table state values:
ID AMOUNT
-------------------------
1 123.4578
2 NULL
2 123.78
1 -8562.85441
2
1 0.0
-------------------------
Column AMOUNT
can be empty as the second last row above depicts.
I want to do a SUM
over the AMOUNT
group by ID
in a query.
The result SUM should be DECIMAL(16,2).
What will be the correct way to do that considering that the value can be both null and empty and also the number of digits after the decimal is not following any fixed format?
It's a duplicate of this question, but the answers given are not complete and not accepted.
Thanks for reading!
if(amount is null OR amount = '') then 0 else amount
, in pseudo-code. this column should be done numerically, though. a numeric column wouldn't allow an "empty" value, which is a string. a number is either null, or an number.