SQL SERVER: How to get list of all month’s name - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

SQL SERVER: How to get list of all month’s name

In this article I am going to explain how to get list of all month’s name in Sql server.


Description:
I want to display the list of all month’s name.

Implementation:

Run the below given query to generate the list of all (12) month’s name:

SELECT
 [Month Number] = number,
 [Month Name] =DATENAME(MONTH, '2016-' + CAST(number as varchar(2)) + '-1')
FROM master..spt_values
WHERE Type = 'P' and number between 1 and 12
ORDER BY Number

OR

Declare @Year VARCHAR(10)
SELECT @Year ='2016'
SELECT [Month Number] = number,[Month Name]= DATENAME(MONTH, cast(@year+'-'+ ltrim(rtrim(CAST(number as varchar(2)))) + '-1' as datetime))
FROM master..spt_values
WHERE Type = 'P' and number between 1 and 12
ORDER BY Number




What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon