Link to home
Start Free TrialLog in
Avatar of wtsumpes
wtsumpes

asked on

How do I sum only negative field values in MS SQL reports

Hi Xperts.

This might be an easy answer for you guys, but its a tough question for me!

I've built a simple SQL report which needs to total wirless accounts which have negative message balances on their unit's.

and then sum only the negative values in order to produce a total of the negative numbers ignoring the positive numbers.

EXAMPLE of what I need:

Record 1 Value  2
Record 2 Value -2
Record 3 Value -2

SUM of ALL records =  -4 which ignores the positive numbers

My current formula doesn't work because it 'sums' everything instead of just negative numbers.

=Sum(Fields!OverageRemain.Value)

Thank you very much for your help.

Bill
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Without seeing your table structure it is a little difficult to know, but something like this should work:

Select Account, SUM(OverageRemain)
From  TableName
Where SIGN(OverageRemain)  != 1
Group By Account
ASKER CERTIFIED SOLUTION
Avatar of amyhxu
amyhxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amyhxu
amyhxu

Have you tried my solution? It should work for you.