title: How can I use a CASE statement in a WHERE clause with IS NULL?
body: <p>Here's my queries, they don't work but I want to do something like this :</p>
  
  <pre><code>SELECT a_field FROM a_table
  WHERE
  ... 
  AND
  CASE
  WHEN a_value_from_another_query IS NULL THEN a_second_field IS NULL
  ELSE a_second_field = a_value_from_another_query
  END
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>SELECT a_field FROM a_table
  WHERE
  ... 
  AND
  CASE a_value_from_another_query
  WHEN NULL THEN a_second_field IS NULL
  ELSE a_second_field = a_value_from_another_query
  END
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>SELECT a_field FROM a_table
  WHERE
  ... 
  AND
  CASE NVL(a_value_from_another_query, 'x')
  WHEN 'x' THEN a_second_field IS NULL
  ELSE a_second_field = a_value_from_another_query
  END
  </code></pre>
  
  <p>When <code>a_value_from_another_query IS NULL</code>, I want to add <code>a_second_field IS NULL</code> to my WHERE clause, when <code>a_value_from_another_query IS NOT NULL</code>, I want to add <code>a_second_field = a_value_from_another_query</code> to my WHERE clause.  How can I achieve this ?</p>