title: Custom ORDER BY Function SQL
body: <p>I have requirements for a custom ORDER BY clause that looks much like this</p>
  
  <p><a href="https://stackoverflow.com/questions/23909406/sql-custom-order-by-clause">SQL Custom Order By Clause</a></p>
  
  <pre><code>SELECT * FROM example
  ORDER BY 
  CASE 
      WHEN name = 'I want this first' THEN 0
      WHEN name = 'I want this second' THEN 1
      WHEN name = 'We get the picture' THEN 2
      ELSE 99   END ASC
  </code></pre>
  
  <p>However, this case statement has grown and I want to be able to reuse the sort order for other queries. </p>
  
  <p>I see my options being</p>
  
  <ol>
  <li>Copy Paste!</li>
  <li>Adding another column to the table specifically for this sort order</li>
  </ol>
  
  <p>In my head, it seems like I should be able to pass a function to perform the sorting logic. But after some searching on SO and google I couldn't find anything and thought this might also help someone else down the road.</p>