Custom order by in SQL server like P, A, L, H

SqlSql ServerSql Order-By

Sql Problem Overview


Not ASC or DESC.... Order by custom...

I have tried using case but not successfully

SELECT * FROM Customers
ORDER BY case country
when 'P' then 1 …

This is what I want:

Sql Solutions


Solution 1 - Sql

SELECT * FROM Customers
ORDER BY case when country = 'P' then 1
              when country = 'A' then 2
              when country = 'L' then 3
              when country = 'H' then 4
              else 5
         end asc

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmhd noufelView Question on Stackoverflow
Solution 1 - Sqljuergen dView Answer on Stackoverflow