Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query: Order by "string" then ascending

Status
Not open for further replies.

L1sta

Technical User
Feb 22, 2007
14
GB
Hi there
This possibly isn't the most difficult of requests, but i cant get it to work
I have a column in a table which will be either "general" or a random string (free text entered by the user).
I need a subform which always has 'General' at the top (if it exsists) and then in ascending alphabetical order.
Hopefully theres a simple way to put this into a SELECT query.
Thanks for any help,
Lista
 
If I understand the question, what you want is to order a list alphabetically, with the exception that the word "General" must be placed at the head of the list regardless of alphabetical order.

Right?

If so, I don't think a SELECT query will do it for you, but a UNION might. Make one SELECT with your conditions AND <field_name> = 'General', and append another SELECT with your conditions AND <field_name> <> 'General' ORDER BY <field_name>. Then your recordset will consist of all records with 'General' followed by all others in alphabetical order.

TMTOWDI - it's not just for Perl any more
 
Something like this (SQL code) ?
SELECT ...
ORDER BY IIf([your column]='General',0,1), [your column]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top