Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

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

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
Sherry
Asked:
Sherry
1 Solution
 
Surendra NathTechnology LeadCommented:
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
 
SherryDeveloperAuthor Commented:
Just what I needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now