title: Nested CASE..WHEN - SQL
body: <ol>
  <li>If Tab1.Col1 = Tab2.Col1 then get the Stats1 field from the Table 2</li>
  <li>If Tab3.Col3 = Tab2.Col3 then get the Stats3 field from the Table 3</li>
  <li>If Tab2.Col2 = substr(Tab3.XYZ,1,2) then pass Stats1 (from above Step 1 as Com_Desc) else Stats3 (from step2 as Com_Desc)</li>
  <li>If Com_Desc derived from step 3 is NULL or Blank, pass -1</li>
  </ol>
  
  <p>I want to implement the above logics using case when statement. Have written the query but unable to populate the -1 value when both stats1 and stats3 is NULL
  Below is my Query -</p>
  
  <pre><code>SELECT 
  (CASE WHEN (Tab2.Col2 = substr(Tab3.XYZ,1,2)
  THEN ((CASE WHEN Tab2.Stats1 is NOT NULL THEN Stats1 
        ELSE (CASE WHEN Tab3.Stats 3 is NOT NULL THEN Stats3
              ELSE -1
              END) 
        END)
   ELSE END)COM_DESC
  FROM Tab1, Tab2, Tab3
  WHERE Tab2.Stats1 IN (SELECT Tab2.Stats1 
                        FROM Tab1, Tab2 WHERE Tab1.Col1 = Tab2.Col1)
  AND Tab3.Stats3 IN (SELECT Tab3.Stats3 
                      FROM Tab2, Tab3 WHERE Tab3.Col3 = Tab2.Col3);
  </code></pre>