Defining a Custom Sort Order

Here are two ways to define a list in the sort order you choose.

Itzik Ben-Gan

October 31, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today


From the Customers table in the Northwind sample database, I want to return the list of customers by country in the custom sort order that Figure 1 shows. How can I define that sort order?

To define the custom sort order, you can use a CASE expression in the ORDER BY clause, as Listing 1 shows. Alternatively, you can create an auxiliary table in which you store your custom sort order, then join the auxiliary table to the Customers table, as Listing 2 shows.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like