Function Returning Month Name in SQL Server

Hello to everyone,

In this article, I will try to give information about the use of the month name function in SQL Server.

In SQL Server, in some cases, you may want to get the month name from the month number. There are other solutions to this, but let’s create our own function.

You can do this easily using the code below.

CREATE FUNCTION fnMonthInfoFunction
    @MonthNumber INT
    DECLARE @MonthName VARCHAR(10);
    SELECT @MonthName = CASE
                        WHEN @MonthNumber = 1 THEN
                        WHEN @MonthNumber = 2 THEN
                        WHEN @MonthNumber = 3 THEN
                        WHEN @MonthNumber = 4 THEN
                        WHEN @MonthNumber = 5 THEN
                        WHEN @MonthNumber = 6 THEN
                        WHEN @MonthNumber = 7 THEN
                        WHEN @MonthNumber = 8 THEN
                        WHEN @MonthNumber = 9 THEN
                        WHEN @MonthNumber = 10 THEN
                        WHEN @MonthNumber = 11 THEN
                        WHEN @MonthNumber = 12 THEN
    RETURN @MonthName;


SELECT dbo.fnMonthInfoFunction(6) AS MonthNameInfo;
SELECT dbo.fnMonthInfoFunction(3) AS MonthNameInfo;
SELECT dbo.fnMonthInfoFunction(12) AS MonthNameInfo;

When you create the above function and run the code, you will see a result similar to the one below.

Function Returning Month Name in SQL Server

As you can see, when the month number is entered, the month name information is sent to us as a text.

Good luck to everyone in business and life.


Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!