CREATE FUNCTION RangeOfMonths
(
@StartDate DATETIME ,
@EndDate DATETIME
)
RETURNS @RangeOfMonths TABLE
(
MonthName VARCHAR(15) ,
YearOfMonth INT
)
BEGIN
; WITH CTE
AS ( SELECT 0 ID , @StartDate Date
UNION ALL
SELECT ID + 1 , DATEADD(mm, ID + 1, @StartDate)
FROM CTE
WHERE LEFT(CONVERT(VARCHAR, DATEADD(mm, ID + 1,@StartDate), 112),6)
Write an Answer
question details
No one has followed this question yet.
Copyright 2022 Redgate Software.
Privacy Policy