title: Case when not returning properly values
body: <p>I have 3 &quot;case when&quot; selects but i'm having troubles with the last one:</p>
  <pre><code>select  
  case  
   when :wprod IN (select cod from products where standard = 'N' and disabled_date is null and classif = 1)
    THEN 
     case when :wprod NOT IN 
     (select cod from invoice where seq in 
     (select invoice_prod from invoice_outrosdocto pout where pout.register = :register and 
     pout.disabled_date is null))
      
  
       -- My problem are below:
        
        THEN  
        CASE WHEN (SELECT * from
        (SELECT selfinvoice FROM invoice WHERE seq =
        (SELECT Max(invoice) FROM invoice WHERE register = :register AND cod = :wprod AND deleted IS NULL))) = 'S'
           THEN 'SA' 
           else 'SB' end
  
  
  -- How can I compare a column (selfinvoice) from the last entry date Max(invoice)?
  -- I tried the selected as shown, it's great when having 'S' or 'N' explicit values, but sometimes
  -- it returns 0 rows (nothing) and by this I can't compare this &quot;case when&quot;
  -- I've also tried Nvl(selfinvoice, 0) but it didn't worked as well
  
  
  
  end  ELSE 'NB' end
  else 'NC' end logic
  , '  ' value 
  from  
  dual group by '  '  
  
  </code></pre>
  <p>Is there any other approach to this problem? Seems like I hit a big concrete wall...
  Thanks in advance.</p>