2

I have a pretty simple question me thinks. I've been looking on the internet, but haven't been able to find anything. I am trying to add an IF statement basically to my Oracle sql.

UPDATE PS_Z_TREND_NOW_TBL a 
  SET STATUS = ( 
 SELECT COUNT(SEC.IS_AW_AUTH_NAME) 
  FROM PS_IS_AW_SECURITY sec 
 WHERE sec.IS_AW_AUTH_NAME LIKE '%Manager%' 

I want to update STATUS so that if COUNT(SEC.IS_AW_AUTH_NAME) is greater than 0 it will insert 'M'. How would I write this?

2
  • 3
    USE CASE statements Commented Sep 30, 2014 at 20:51
  • Are you sure that you want PS_Z_TREND_NOW_TBL updated for all records if the COUNT(SEC.IS_AW_AUTH_NAME) is greater than 0? Could it be that you want this done only when a.is_aw_auth_name = sec.is_aw_auth_name. Could it be that you want to use a correlated subquery in your where clause or merge statement? Commented Sep 30, 2014 at 21:19

1 Answer 1

3

With Case statements.

UPDATE PS_Z_TREND_NOW_TBL a 
  SET STATUS = ( CASE WHEN COUNT(SEC.IS_AW_AUTH_NAME)  > 0 then 'M'
                 ELSE null END )
FROM PS_IS_AW_SECURITY sec 
WHERE sec.IS_AW_AUTH_NAME LIKE '%Manager%'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.