Logic
The logic is if an order is cancelled then return 0 otherwise return the owed value - the paid value
Small query
CASE WHEN d.cancelled = 'TRUE'
THEN '0'
ELSE (to_char(b.owed)) - (to_char(d.paid))
END AS balance,
Getting the error
ORA-00932: inconsistent datatypes: expected CHAR got NUMBER 00932. 00000 - "inconsistent datatypes: expected %s got %s" *Cause:
*Action: Error at Line: 25 Column: 58
NUMBER
as the balance? Or aVARCHAR2
? YourTHEN
is returning aVARCHAR2
, yourELSE
is returning aNUMBER
. You'll need to ensure that both paths return a value with the same data type. It's just not clear which data type you intend to return. – Justin Cave