Solved

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

Posted on 2014-01-29
2
135 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 250 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now