Query Reg. Fetching Monthname

  • I need to fetch the monthname in full

    like january, march.

    I need to pass only the month(numeric).

    Ex.

    DateName(month,GetDate())

    fetches the month as September.

    Likewise

    I need to get the month

    given only the month number.

    Like

    datename(month,monthnumber)

    Thanx in Advance

  • u create it user defined function for this req.In my knowledge no other function like ur req.

  • DECLARE @monthnumber int

    SET @monthnumber = 9

    SELECT DATENAME(month,DATEADD(month,@monthnumber - 1,0))

    Far away is close at hand in the images of elsewhere.
    Anon.

  • The most effective way is to have a date dimension table with all the math and breakouts on a date already done.  Or, if you do not need that level of control, simply create a table to hold the months like this:

    Month_Nbr

    Month_Name

    Month_Abbrev

    Now you will not have to use a function that is called for every line that is returned, you simply do a SQL join.

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

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