I have a a column of data that has both Positive and Negative numbers. I need SQL to find and add only the positive values.
I am trying to add up Total Credits (Negative Number) and Total Debits (Positive Number) for a JE. So I have a single column (AMOUNT) that has both Positive and Negative amounts. In my TOTALCREDIT field I need code to tell it find and sum only the Positive numbers from the AMOUNT column and for the TOTALCREDIT field I need to find and add only the Negative numbers from the AMOUNT column. I have tried variations of the following but it always returns 0.
TOTALDEBIT
sum (case when AMOUNT >= 0 then AMOUNT else 0 end) as positive
TOTALCREDIT
sum (case when AMOUNT < 0 then AMOUNT else 0 end) as negative
So if the AMOUNT column has 25, -25, 30, -30
- The TOTALDEBIT field will sum to 55
- The TOTALCREDIT Field will sum to -55
So I need 1 of string code of for each field.