title: ORDER BY with CASE clause
body: <p>I want to create a dynamic order by statement.    </p>
  
  <p>Its purpose is to read a table of daily schedule overrides (0 to * records) and decide to use a global override or a store override, for selected day.  </p>
  
  <p>I thought of using a case clause like below but its not working as expected.</p>
  
  <pre><code>select * from schedule sdl 
  where day = 3
  and (sdl.store_id = 23331 or sdl.store_id is null)
  order by
  case when sdl.force is true 
  then 'sdl.store_id nulls first' 
  else 'sdl.store_id nulls last'
  end 
  limit 1
  </code></pre>
  
  <p>Is it possible to create an order-by statement using a case statement? Or maybe there is a better approach on the subject.</p>