title: Oracle (SQL Statements) - Using CASE with WHERE CLAUSE
body: <p><em>Dear Experts,
  I preparing an SQL report to display the data with Format_Check validations using CASE. I have provided the example,issues and expectation below:</em></p>
  
  <p><strong>Table Structure:</strong><a href="https://i.stack.imgur.com/9XIRH.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p><strong>SQL Statement:</strong></p>
  
  <pre><code>SELECT 
  
  ID,PRODUCT,COMMENTS
  
  CASE WHEN SUBSTR(COMMENTS,1,35)=REGEXP_SUBSTR (COMMENTS,'(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\s)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\s)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\s)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)',1,1)
  AND
  LENGTH(TRIM(REGEXP_SUBSTR (COMMENTS, '(\S*)(\s)', 1, 2)))=8 
  AND
  REGEXP_LIKE(TRIM(REGEXP_SUBSTR (COMMENTS, '(\S*)(\s)', 1, 1)),'(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)')
  THEN 'Correct Format'
  ELSE 'Incorrect_Format'
  END AS Format_Check
  
  FROM TEST_TABLE
  </code></pre>
  
  <p><strong>SQL Output:</strong>
  <a href="https://i.stack.imgur.com/tkn65.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p><strong>SQL Output Explanation:</strong></p>
  
  <blockquote>
    <ol>
    <li><p>Checks whether COMMENTS column is 35 Character long, also checks the format numbers and spaces. SUBSTR(COMMENTS,1,35)=REGEXP_SUBSTR
    (COMMENTS,'(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\s)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\s)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\s)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)',1,1)</p></li>
    <li><p>Checks whether the comments after first space is 8 characters long LENGTH(TRIM(REGEXP_SUBSTR (COMMENTS, '(\S*)(\s)', 1, 2)))=8 </p></li>
    <li><p>Checks the first 8 characters is digit/number. REGEXP_LIKE(TRIM(REGEXP_SUBSTR (COMMENTS, '(\S*)(\s)', 1,
    1)),'(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)')</p></li>
    </ol>
  </blockquote>
  
  <p><strong>Expectation:</strong></p>
  
  <p><em>I need only the 'Incorrect Format' comments to be displayed when the SQL is executed, I don't wish to see the 'Correct Format' comments. However I need your advise on whether this case be used with WHERE clause to display only incorrect format COMMENTS alone.
  I referred previous queries related to WHERE and CASE, however I can't figure out on how pass my case in WHERE clause.
  Thanks for your help.</em></p>