Hey all,
So I'm trying to check some columns together to ensure that the sums of A & B equal to row C, for each given currency.
Table Sales;
Currency | ColA | ColB | ColC |
AUD | 50,000 | 50,000 | 100,000 |
CAD | {null} | 20,000 | 20,000 |
MZN | 30,000 | {null} | 30,000 |
YER | 10,000 | 10,000 | 20,000 |
Query that I can't seem to get working properly:
SELECT Currency, CAST((SUM)CASE WHEN((coalesce(ColA,0)) + (coalesce(ColB,0))) = (coalesce(ColC,0)) THEN 0 ELSE SUM((coalesce(ColA,0)) + (coalesce(ColB,0))) - (coalesce(ColC,0) END AS sales_check)
The output that I'd like to get:
Currency | sales_check |
AUD | 0 |
CAD | 0 |
MZN | 0 |
YER | 0 |
Thanks,