If statement in select (ORACLE) If statement in select (ORACLE) sql sql

If statement in select (ORACLE)


SELECT (CASE WHEN ISSUE_DIVISION = ISSUE_DIVISION_2 THEN 1 ELSE 0 END) AS ISSUES    --  <add any columns to outer select from inner query>   FROM (  -- your query here --   select 'CARAT Issue Open' issue_comment, ...., ...,           substr(gcrs.stream_name,1,case when instr(gcrs.stream_name,' (')=0 then 100 else  instr(gcrs.stream_name,' (')-1 end) ISSUE_DIVISION,          case when gcrs.STREAM_NAME like 'NON-GT%' THEN 'NON-GT' ELSE gcrs.STREAM_NAME END as ISSUE_DIVISION_2     from ....    where UPPER(ISSUE_STATUS) like '%OPEN%' ) WHERE... -- optional --


So simple you can use case statement here.

CASE WHEN ISSUE_DIVISION = ISSUE_DIVISION_2 THEN          CASE WHEN  ISSUE_DIVISION is null then "Null Value found" //give your option         Else 1 EndELSE 0 END As Issue_Division_Result


use the variable, Oracle does not support SQL in that context without an INTO. With a properly named variable your code will be more legible anyway.