Oracle query with if then else

How can I have an if then else  for  the following sql query
       Select
       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?
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.

_agx_Commented:
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
0
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.
SELECT CASE 
         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

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
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?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Sam OZAuthor Commented:
Hi Johnson. Also I tried changing the order . For some reason, it does not reflect on the result
0
johnsoneSenior Oracle DBACommented:
A CASE is essentially an if-then-else.  Can you provide sample data to show how it isn't working?
1
_agx_Commented:
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.
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
SQL

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.