Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Order by specific word, then alphabetically Expand / Collapse
Author
Message
Posted Monday, October 19, 2009 3:57 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, November 26, 2009 1:22 PM
Points: 20, Visits: 34
I have a lot of parameters in a table. I query the database to popuplate dropdown boxes with specific options. Some dropdowns have an option "OTHER". How do I query the database to return "OTHER" as the first option, and then sort alphabetically? eg:

Select your gender:
OTHER
MALE
FEMALE

Right now I only know how to order asc or desc or as the data was entered by ordering by the ID. Is there a way of doing what I want to do? I'm using SQL 2008 Enterprise.
Post #805311
Posted Monday, October 19, 2009 5:01 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 22, 2014 9:38 AM
Points: 1,525, Visits: 4,071
Something like this:

ORDER BY CASE WHEN Col='Other' THEN 1 ELSE 2 END, Col



Seth Phelabaum
Consistency is only a virtue if you're not a screwup.

Links: How to Post Sample Data :: Running Totals :: Tally Table :: Cross Tabs/Pivots :: String Concatenation
Post #805328
Posted Tuesday, October 20, 2009 9:09 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, November 26, 2009 1:22 PM
Points: 20, Visits: 34
Thank you! Worked like a charm!
Post #805806
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse