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)?

thanks
LVL 6
zell71Asked:
Who is Participating?

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

x
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.

silemoneCommented:
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
silemoneCommented:
here's a link to show you how to use:

http://technet.microsoft.com/en-us/library/ms181765.aspx
Patrick MatthewsCommented:
In SQL Server, you would use CASE...


CASE WHEN (TotalNetSales + TotalRefundedSales) < 0 AND (TotalMargin + TotalRefundedMargin) < 0 THEN
     ELSE
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 :)
silemoneCommented:
here if/else...this example should be exactly what you're looking for...has a similar expression in it...

http://doc.ddart.net/mssql/sql70/ia-iz_4.htm
silemoneCommented:
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.