Click here to Skip to main content
15,906,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i just want to order the query out put using enumeration value {september, october, november, december}
so i write

select * from fee order by month {september, october, november, december}

since it will simply dispaly the record in alphabetic order i.e. starting from April, but since our calender begins from September i want it to be the first record to be displayed. can anyone help me? Thanks!
Posted

I'm not sure what you're trying to achieve, but you try converting the months into integers and sorting on it like that.

Otherwise, you could create a table variable with the months and a second column indicating order. Join that up to your data and then order by the temporary tables order column.

Either should do it.
 
Share this answer
 
v2
Comments
getrelax 11-Aug-10 13:04pm    
i think as u said if i create another table with with 2 columns (i.e. an int field to sort as i wish, & month) and if i join it with the main table it will work. but i am interested to know weather i can give an enum value for sorting purpose of certain field. I think i have seen it before, is that possible?
Andrew Rissing 12-Aug-10 10:53am    
I'm not aware of enum support for MS SQL, but other DB's may have it.
I'm not exactly sure the order you are going for, but you can do a custom ordering based on the month. You could do something like this:
SQL
SELECT
    *
FROM Fee
ORDER BY
    CASE Month
        WHEN 'September' THEN 1
        WHEN 'April' THEN 2
        -- ...
        ELSE 999
    END AS MonthOrder ASC

Not sure if the syntax is exactly correct, but you get the idea.
 
Share this answer
 
v2
Comments
getrelax 11-Aug-10 13:32pm    
i am using the code in vb6 and it generates the following error
Error 5000 : Error in processing report.
[ Extended Info:[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression '(case fee.month when 'september' then 1 when 'october' then 2 else 999 END AS MonthOrder ASC)'.]
AspDotNetDev 11-Aug-10 14:04pm    
Didn't know you are using Access. It seems, in Access, you can make use of the Switch function rather than the Case statement: http://www.webcheatsheet.com/SQL/access_functions/switch.php
getrelax 12-Aug-10 9:45am    
Thanks dear, it works perfect!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900