Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting a 0 value on negative results for an aggregation in a query

Posted on 2014-01-29
2
Medium Priority
?
143 Views
Last Modified: 2014-01-29
I have a query that calculates the debt balance:

Total Amt - Amt Paid - WriteOff Amt = Debt Balance

How can I tell it to give me a 0 balance if it's negative or < 0?

I can only find help on using the SET and a parameter.
0
Comment
Question by:Sherry
2 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 750 total points
ID: 39819197
you can write as below

select @t = CASE WHEN (Total Amt - Amt Paid - WriteOff Amt) < 0 THEN 0 ELSE Total Amt - Amt Paid - WriteOff Amt END

Open in new window

0
 

Author Closing Comment

by:Sherry
ID: 39819214
Just what I needed.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

963 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