title: Ordering query result by list of values
body: <p>I'm working on a sql query that is passed a list of values as a parameter, like</p>
  
  <pre><code>select * 
  from ProductGroups
  where GroupID in (24,12,7,14,65)
  </code></pre>
  
  <p>This list is constructed of relations used througout the database, and must be kept in this order.</p>
  
  <p>I would like to order the results by this list. I only need the first result, but it could be the one with GroupId 7 in this case. </p>
  
  <p>I can't query like </p>
  
  <pre><code>order by (24,12,7,14,65).indexOf(GroupId)
  </code></pre>
  
  <p>Does anyone know how to do this?</p>
  
  <p><strong>Additional info:</strong><br>
  Building a join works and running it in the mssql query editor, but...</p>
  
  <p>Due to limitiations of the software sending the query to mssql, I have to pass it to some internal query builder as 1 parameter, thus "24,12,7,14,65". And I don't know upfront how many numbers there will be in this list, could be 2, could be 20. </p>