Specify order of rows returned in MS SQL Server


/ Published in: SQL

Similar to "FIND_IN_SET" from MySQL.


Copy this code and paste it in your HTML
  1. SELECT Name
  2. FROM People
  3. WHERE Name IN ('Bob', 'Mary', 'Joe')
  4. ORDER BY
  5. CASE Name
  6. WHEN 'Mary' THEN 1
  7. WHEN 'Joe' THEN 2
  8. WHEN 'Bob' THEN 3
  9. END

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.