Select query order by month

  • I have month column. so i want to display these months in a calender order

    like

    jan

    feb

    mar

    apr

  • Create a table such as....

    Create Table MonthOrder

    (

    MonthCode char(3),

    SortOrder tinyint)

    insert into MonthOrder('Jan',1)

    insert into MonthOrder('Feb',2)

    insert into MonthOrder('Mar',3)

    etc...

    Join to that , and order by sortorder....



    Clear Sky SQL
    My Blog[/url]

  • Hi

    If you are in a position to can't change the table structure , lke you have month column but can't add the sort order column , give the order by with case statement

    select mon from tm

    order by case mon

    when 'jan' then 1

    when 'feb' then 2

    when 'nov' then 3

    ------

    ------

    end

    -- mon is the column name in the table tm.

    Regards,

    MC

    Thanks & Regards,
    MC

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply