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
Best Answer
Try this, either your case should return number or varchar, right now your case return '0' as varchar and else as number. Either both should return a varchar or both should return a number.
When Both return varchar
OR
When Both return number
OR
When Both return number