title: Order by condition for two DATETIME columns
body: <p>I read <a href="https://stackoverflow.com/questions/2367457/order-by-condition">ORDER BY condition</a> and <a href="https://stackoverflow.com/questions/4213270/how-to-add-condition-in-order-by">How to add condition in &#39;order by&#39;?</a> but these don't answer to my issue.</p>
  
  <p>I have 2 datetime columns called <code>CREATION_DATE</code> and <code>UPDATE_DATE</code>.</p>
  
  <p>I want to sort (using <code>ORDER BY</code> clause) by :</p>
  
  <ul>
  <li><p><code>CREATION_DATE</code> if <code>CREATION_DATE = UPDATE_DATE</code></p>
  
  <p>or</p></li>
  <li><p><code>UPDATE_DATE</code> in other case.</p></li>
  </ul>
  
  <p>I wrote </p>
  
  <pre><code>SELECT * FROM Table1
  ORDER BY
  CASE Table1.CREATION_DATE
      WHEN Table1.CREATION_DATE = Table1.UPDATE_DATE THEN Table1.CREATION_DATE
      ELSE Table1.UPDATE_DATE
  END ASC
  </code></pre>
  
  <p>but it does not work, I get an error at the <code>=</code> symbol. </p>
  
  <p>I tried with other operators... Of course, I make mistake but I don't know if is correct to use operators in <code>WHEN</code> statement.</p>
  
  <p>Is not accepted operators in <code>WHEN</code> ?</p>
  
  <p>Thank you</p>