You can print all the names of the months in the SQL server by using SQL Recursive CTE.
Here is the simple SQL Query,
USE your_database
GO
WITH CTE_MonthName(Number, MonthName ) AS
(
SELECT 0, DATENAME(MONTH, DATEADD(MONTH, 0, DATEFROMPARTS(YEAR(GETDATE()), 1, 1)))
UNION ALL
SELECT Number+1, DATENAME(MONTH, DATEADD(MONTH, Number+1, DATEFROMPARTS(YEAR(GETDATE()), 1, 1))) FROM CTE_MonthName WHERE Number < 11
)
SELECT MonthName FROM CTE_MonthName
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
You can print all the names of the months in the SQL server by using SQL Recursive CTE.
Here is the simple SQL Query,
Output:
Also, Read: SQL Query to print Week days.