Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to modify the Order By clause

Author  Topic 

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2011-11-28 : 09:44:17
I have a Select which returns Names, some of which are preceded by (Vacant). For example,
Smith, John
Jones, Scott
(Vacant) Doe, Jane

I want the names to be alphabetized, except that I want all the ones preceded by (Vacant) to be at the bottom of the list.

When I just say Order by Name, it alphabetizes the open paren to the top of the list.
Any ideas on how to do this? If it helps, I don't care so much about the alphabetizing of the (vacant) names. I just want them all at the bottom.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-11-28 : 10:05:15
SELECT Name FROM Names
ORDER BY CASE WHEN Name LIKE '(Vacant)%' THEN 1 ELSE 0 END,
Name
Go to Top of Page

DaveBF
Yak Posting Veteran

89 Posts

Posted - 2011-11-28 : 10:13:59
Perfect. Thank you!
Go to Top of Page
   

- Advertisement -