order by dates

  • Hi,

    Can some one pleas help me out to order by the month and year.

    Actually i have date range from [Jan-2009],[Feb-2009],[Mar-2009]-------[Feb-2010].

    I need to order by these results such a way that [Feb-2010],[Jan-2010]-----[Jan-2009].

    Thanks

    Kp

  • Does your column contains values as Feb 2010, Jan 2010 or the column is a datetime datatype?


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • The Columns are string....I have stored all these into one string variable

  • Something like this?

    declare @tbl table (datestring varchar(10))

    insert into @tbl values ('Jan-2009')

    insert into @tbl values ('Feb-2009')

    insert into @tbl values ('Mar-2009')

    insert into @tbl values ('Feb-2010')

    select datestring

    from @tbl

    order by cast(replace(datestring, '-', ' ') as datetime) desc

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • Thanks Much...That works

Viewing 5 posts - 1 through 4 (of 4 total)

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