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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • 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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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