SQL Case Statement Compare

If I have
      AgtNo      Sales      Tier1      Tier2
      123                 10                    5      8

So agent 123 sold 10 units and if an agent's sales exceeds Tier1 they get 200 bonus if they exceed Tier2 they get 500. If they hit Tier 2 they are excluded from Tier 1. In other words this agent would win 500 and NOT 700 (200 + 500)
I want to write a Case Statement
Case When Sales >= Tier1 Then 200
          When Sales >= Tier2 The 500  else 0 end as Payout.

My problem is that Case statement produces a 200 result, thus ignores the Tier2 portion.
What am I doing wrong?
Thanks
SeTechAnalystAsked:
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.

Kent OlsenDBACommented:
The tests occur in the order they're programmed.

Case When Sales >= Tier2 Then 500
          When Sales >= Tier1 Then 200  else 0 end as Payout.

That should work just fine.  :)

Good Luck,
Kent
0

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
SeTechAnalystAuthor Commented:
Works Perfect - thanks
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
the root of the issue was that you forgot to put the limit condition:

Case When Sales >= Tier1 and Sales < Tier2 Then 200
     When Sales >= Tier2 Then 500  else 0 end as Payout

but we usually use the approach as what Kent had proposed above. it's much more easier to code.
0
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
Microsoft SQL Server 2008

From novice to tech pro — start learning today.