Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2005-03-25
Medium Priority
Last Modified: 2012-06-27
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.


Thank you very much for your help.

Question by:wtsumpes
  • 2
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13634688
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
LVL 14

Accepted Solution

amyhxu earned 2000 total points
ID: 13658876
=  Sum(iif(Fields!OverageRemain.Value >= 0, 0, Fields!OverageRemain.Value))
LVL 14

Expert Comment

ID: 13688675
Have you tried my solution? It should work for you.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I am very much excited today since I'm going to share something very exciting Tool used for Analytical Reporting and that's nothing but MICROSTRATEGY. Actually there are lot of other tools available in the market for Reporting Such as Co…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question