Oracle query with if then else

How can I have an if then else  for  the following sql query
       case when Status is not null  then 2000    --- condition 1
        case when RevStatus in (10,20)  then RevStatus * 50   -- condition 2
        else StateNo end  StateNoDerived
      From Docs
   If  both condition 1 and 2 are met I need to get value as 2000 ( based on condiition 1 )
Sam OZAsked:
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.

Can't you combine the first two conditions with AND?

SELECT  CASE WHEN Status IS NOT NULL AND RevStatus IN (10,20) THEN 2000
                         ELSE 0 --- Return whatever you want here
               END AS TheResultNameHere
FROM    Docs
johnsoneSenior Oracle DBACommented:
Not sure I quite understand what you are looking for.  CASE works in order, so the first one it finds it takes.
         WHEN ( status IS NOT NULL ) 
               OR ( status IS NOT NULL 
                    AND revstatus IN ( 10, 20 ) ) THEN 2000 
         WHEN revstatus IN ( 10, 20 ) THEN revstatus * 50 
         ELSE stateno 
       END StateNoDerived 
FROM   docs 

Open in new window

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
Sam OZAuthor Commented:
Hi Agx, Johnson I have a few more conditions. So your approach , though works may be a little cumbersome . Is there areally no clean way of using If then else  ( Or case else ) in oracle?
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!

Sam OZAuthor Commented:
Hi Johnson. Also I tried changing the order . For some reason, it does not reflect on the result
johnsoneSenior Oracle DBACommented:
A CASE is essentially an if-then-else.  Can you provide sample data to show how it isn't working?
though works may be a little cumbersome

I agree with johnsone in that CASE essentially is what you're looking for, but ... it'd help to see the full conditions along with sample code. That way we could see why it's cumbersome/not working and possibly suggest a way to improve it.
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

From novice to tech pro — start learning today.