Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2005
    Posts
    33

    Unanswered: name of month from int value

    What is the best way to get the month name from an int value
    within a mssql statement ?
    (there is no need to consider the language settings)

    e.g.
    1 -> January
    11 -> Novembre

    My first approach seems to work but is very ugly:
    CASE WHEN my_month_int<10
    THEN DATENAME(month,"20000"+cast(my_month_int as varchar(2))+"15 00:00:00")
    ELSE DATENAME(month,"2000"+cast(my_month_int as varchar(2))+"15 00:00:00")
    END AS my_month_name

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select datename(m,dateadd(m,my_month_int-1,0)) as my_month_name

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2005
    Posts
    33
    Thanx a lot, r937. Nice trick.

Posting Permissions

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