SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    bangalore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to sort month and year

    Dear all
    i have data likes this
    post_month post_ year
    january 2006
    .
    .
    december 2006
    january 2007
    february 2007

    i need to write a query to display as follows

    january2006
    .
    .
    december2006
    january2007
    february2007

    thanks in advance

    regards
    sona

    .

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select post_month 
         , post_ year
      from daTable
    order
        by post_year
         , case when post_month = 'January' then 1
                when post_month = 'February' then 2
                when post_month = 'March' then 3
                when post_month = 'April' then 4
                when post_month = 'May' then 5
                when post_month = 'June' then 6
                when post_month = 'July' then 7
                when post_month = 'August' then 8
                when post_month = 'September' then 9
                when post_month = 'October' then 10
                when post_month = 'November' then 11
                when post_month = 'December' then 12
                else 99 end
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •