Technical Article

Month Name

,

This Function will return the Month Name for month number input

Month Names
Month CodeMonth Name
01January
02Feburary
03March
04April
05May
06June
07July
08August
09September
10October
11November
12December
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fn_MonthName]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[Fn_MonthName]
go
Create function Fn_MonthName (@MonthCode varchar(2))
Returns Varchar (15)
As
/*------------------------------------------------------------------------------------------------------------------------------------------
** SQLVersion : SQL 2000
** Function    : Fn_FinMonth
** Author     : Kartik M Kumar
** DateTime    : 29 January 2011 21:27
** Version    : 1.1
** Purpose    : To get the Month Name from the respective calander month
** ToCheck    :
** Changes    : 
------------------------------------------------------------------------------------------------------------------------------------------*/ 
/*
-- Start of Debugging Stuff
    Declare @MonthCode varchar(2)
    Set @MonthCode = '03' -- Pass the Month Number as Input
-- End of Debugging Stuff
*/Begin
    Declare @MonthName varchar(15)
    DECLARE @IMonthCd as int
    set @IMonthCd = cast(@MonthCode as Int)
    Select @MonthName = case @IMonthCd 
        when 1 then 'January'
        when 2 then 'Feburary'
        when 3 then 'March'
        when 4 then 'April'
        when 5 then 'May'
        when 6 then 'June'
        when 7 then 'July'
        when 8 then 'August'
        when 9 then 'September'
        when 10 then 'October'
        when 11 then 'November'
        when 12 then 'December' 
                end
Return Isnull(@MonthName, 'InvalidMonth')
end
go

Rate

1.47 (15)

You rated this post out of 5. Change rating

Share

Share

Rate

1.47 (15)

You rated this post out of 5. Change rating