SQL if statement?

hi, using a sql script to calc a margin as a %..
so its something like:

((TotalMargin + TotalRefundedMargin) / nullif((TotalNetSales+ TotalRefundedSales),0)) * 100 AS [Margin%],

however, the problem occurs when TotalNetSales+ TotalRefundedSales < 0 and TotalMargin + TotalRefundedMargin < 0..
how can i do a check to see if both these figures are less than 0...set Margin% as 0 (zero)?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

use case statement...Case   when   <-- used like if statements...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
here's a link to show you how to use:

Patrick MatthewsCommented:
In SQL Server, you would use CASE...

CASE WHEN (TotalNetSales + TotalRefundedSales) < 0 AND (TotalMargin + TotalRefundedMargin) < 0 THEN
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Patrick MatthewsCommented:
Too slow :)
here if/else...this example should be exactly what you're looking for...has a similar expression in it...

but again, i as stated, most times, Case when statement but if you want if/else, there you have it in the above link...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.