PDA

View Full Version : Solved: sql qurey to arrange by names



shamsam1
08-22-2008, 05:12 AM
i have month table with data type varchar

month1
January
march
December
February
October
September
may
march

i want sql query to arrange month according to month list(jan,feb,march,april):think:

Demosthine
09-27-2008, 07:04 PM
Evening There.

The easiest way to do this is to add a second Field to your table that holds the data for your month number. Your table would look something like this...

MonthID MonthName
1 January
3 March
12 December
2 February
10 October
9 September
5 May

From there, you can run the following statement and it will provide the record in the order of the Month's numerical value, ascending from 1 to 12.

"SELECT MonthName FROM Months ORDER BY MonthID ASC;"

Good Luck.
Scott

shamsam1
09-27-2008, 09:41 PM
thanks i already have answer

ORDER BY
CASE MONTH_FIELD
WHEN 'JANUARY' THEN '1'
WHEN 'FEBRUARY' THEN '2'
...
...
...
END

Bob Phillips
09-28-2008, 03:48 PM
Another way



ORDER BY Month(DateValue(""01-"" & Month_Field))