In
this article I am going to explain how to get list of all month’s name in Sql
server.
In
the previous article I have explained how to get year calendar with months nameand number of days in sql server, how to validate corporate or business emailaddress in asp.net using RegularExpression, how to show and hide the passwordon checkbox click using Jquery in asp.net and how to get month calendar withweek day 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
No comments:
Post a Comment