CREATE PROCEDURE RetailDateDim
      @beginDate DATE = '2010-01-01', 
      @endDate DATE = '2030-12-31', 
      @FiscalYearOffsetInMonths INT = 0, 
      @YearFirstInStringFormat INT = 1 ,
      @WeekStartDay INT = 1 --Day of week number, Sun=1, Mon=2, Tue=3, Wed=4, Thu=5, Fri=6, Sat=7
    
AS




DECLARE @ret TABLE
    (
      -- Date is the granularity
      [DimDateID] INT NOT NULL PRIMARY KEY	-- 20100101
      ,
      [Date] DATE						-- 01/01/2010
      ,
      [DateShortName] VARCHAR(55)					-- 01/01/2010
      ,
      [DateLongName] VARCHAR(55)					-- Friday, January 1, 2010
      ,
      [JulianDate] INT							-- 
      ,
      [JulianDateModified] INT							-- 
	-- Calendar
	-- Year
      ,
      [YearKey] INT							-- 2010
      ,
      [YearName] VARCHAR(55)					-- 2010
      ,
      [YearStartDate] DATE						-- 01/01/2010
      ,
      [YearEndDate] DATE						-- 12/31/2010
      ,
      [YearSeqNo] INT							-- XXX  Sequential Year number as offset from Year starting 01/01/1753
	-- Quarter
      ,
      [YearQuarterKey] INT							-- 20101
      ,
      [YearQuarterName] VARCHAR(55)					-- 2010 Q1
      ,
      [QuarterOfYearKey] INT							-- 41
      ,
      [QuarterOfYearName] VARCHAR(55)					-- Q1
      ,
      [YearQuarterStartDate] DATE						-- 01/01/2010
      ,
      [YearQuarterEndDate] DATE						-- 03/31/2010
      ,
      [YearQuarterSeqNo] INT							-- XXX  Sequential Quarter number as offset from Year starting 01/01/1753
	-- Month
      ,
      [YearMonthKey] INT							-- 201001
      ,
      [YearMonthShortName] VARCHAR(55)					-- Jan 2010
      ,
      [YearMonthLongName] VARCHAR(55)					-- January 2010
      ,
      [MonthOfYearKey] INT							-- 1201
      ,
      [MonthOfYearShortName] VARCHAR(55)					-- Jan
      ,
      [MonthOfYearLongName] VARCHAR(55)					-- January
      ,
      [YearMonthStartDate] DATE						-- 01/01/2010
      ,
      [YearMonthEndDate] DATE						-- 01/31/2010
      ,
      [YearMonthSeqNo] INT							-- XXX  Sequential Month number as offset from Year starting 01/01/1753
	-- Week
      ,
      [YearWeekKey] INT							-- 20105201
      ,
      [YearWeekShortName] VARCHAR(55)					-- W1 2010
      ,
      [YearWeekLongName] VARCHAR(55)					-- Week 1, 2010
      ,
      [YearWeekStartDate] DATE						-- 01/01/2010
      ,
      [YearWeekEndDate] DATE						-- 01/01/2010
      ,
      [YearWeekSeqNo] INT							-- XXX  Sequential Week number as offset from Year starting 01/01/1753
      ,
      [WeekOfYearKey] INT 
	  ,
      [WeekOfYearShortName] VARCHAR(55) 
	  ,
      [WeekOfYearLongName] VARCHAR(55)
	-- Day
      ,
      [YearDOYKey] INT							-- 2010001
      ,
      [YearDOYShortName] VARCHAR(55)					-- D1 2010
      ,
      [YearDOYLongName] VARCHAR(55)					-- Day 1, 2010
      ,
      [DayOfYearKey] INT							-- 365001
      ,
      [DayOfYearName] VARCHAR(55)					-- Day 1
      ,
      [DayOfMonthKey] INT							-- 3101
      ,
      [DayOfMonthName] VARCHAR(55)					-- Day 1
      ,
      [DayOfWeekKey] INT							-- 76
      ,
      [DayOfWeekName] VARCHAR(55)					-- Friday
	  ,
	  [RetailWeek] INT
	  ,
	  [RetailYear] INT
	  ,
      [IsWeekend] INT 
	  ,
      [IsHoliday] INT 
	  ,
      [HolidayName] VARCHAR(255) 
	  ,
      [IsLeapYear] INT
	  ,
	  [CompDate] DATE
	  ,
	  [CompDateID] INT
    )
--This section creates the dates between begin date and end date and assigns retail year and week
    BEGIN
		DECLARE @originalbegin DATE = @beginDate
		SET @beginDate = DATEADD(day,-372,@beginDate)
        DECLARE @EarliestPossibleDate DATE = '1753-01-01' 
        DECLARE @ModifiedJulianDateStart DATE = '1858-11-17'
		DECLARE @StartYearFeb1 DATE = CAST(CONCAT(STR(Year(@beginDate)),'-02-01') AS DATE)
		DECLARE @RetailYearStart DATE = CASE WHEN MONTH(@beginDate) <> 1 THEN
									CASE WHEN DATEPART(DW, @StartYearFeb1) <=4 THEN DATEADD(WEEK, DATEDIFF(WEEK, 0, @StartYearFeb1), 0)-1 ELSE DATEADD(WEEK, DATEDIFF(WEEK, 0, @StartYearFeb1), 0)+6 END
									   ELSE CASE WHEN DATEPART(DW, DATEADD(year,-1,@StartYearFeb1)) <=4 THEN DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(year,-1,@StartYearFeb1)), 0)-1 ELSE DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(year,-1,@StartYearFeb1)), 0)+6 END
									   END --- Retail week starts the Monday of the week that includes Feb 1, unless there are more than 4 days of January in that week.  If there are more than 4 days of January in that week, then the retail year begins on the Monday following the first of February
		DECLARE @RETAIL_WEEK_NUMBER INT = 1
		DECLARE @RETAIL_YEAR INT = DATEPART(YEAR, DATEADD(day,6,@RetailYearStart))
		DECLARE @DATES_TABLE TABLE (TheDate DATE, FiscalDate DATE, YearStartDate DATE)
		DECLARE @DateNumber INT = DATEPART(DW, @beginDate)
		DECLARE @RetailDatesTable TABLE (TheDate DATE, FiscalDate DATE, YearStartDate DATE, RetailWeek INT, RetailYear INT)



BEGIN
	WHILE @beginDate <= @endDate
	BEGIN
		SET @RETAIL_WEEK_NUMBER = DATEDIFF(week,@RetailYearStart,@beginDate)+1
		IF @RETAIL_WEEK_NUMBER = 53
		BEGIN
			IF DAY(@beginDate)>28
			BEGIN
				SET @RETAIL_WEEK_NUMBER = 1
			END
			IF DAY(@beginDate)<=28
			BEGIN
				SET @RETAIL_WEEK_NUMBER = 53
				--There were more than 4 days of Jan in week 53. Adding week 53
			END
		END
		IF @RETAIL_WEEK_NUMBER = 1 
		BEGIN
			SET @RETAIL_YEAR = @RETAIL_YEAR + 1
		END;

		WITH cte AS(
		SELECT @beginDate AS TheDate
			,@DateNumber as date_nbr
			,DATEADD(MONTH, -@FiscalYearOffsetInMonths,@beginDate) AS FiscalDate 
            ,DATEADD(YEAR, DATEDIFF(YEAR, 0, @beginDate), 0) AS YearStartDate
		UNION ALL
		SELECT DATEADD(DAY, 1, TheDate)
			,date_nbr +1
			,DATEADD(DAY, 1, FiscalDate) 
            ,DATEADD(YEAR,DATEDIFF(YEAR, 0,DATEADD(DAY, 1, TheDate)), 0)
		FROM cte
		WHERE date_nbr <7
		)
		INSERT INTO @DATES_TABLE
			SELECT TheDate, FiscalDate, YearStartDate
			FROM cte
			ORDER BY TheDate ASC

		INSERT INTO @RetailDatesTable
		SELECT TheDate, FiscalDate, YearStartDate, @RETAIL_WEEK_NUMBER, @RETAIL_YEAR FROM @DATES_TABLE;

		SET @beginDate = DATEADD(DAY, 7, DATEADD(WEEK, DATEDIFF(WEEK, 0, @beginDate), 0)-1)
		SET @RETAIL_WEEK_NUMBER = @RETAIL_WEEK_NUMBER + 1
		SET @StartYearFeb1 = CAST(CONCAT(STR(Year(@beginDate)),'-02-01') AS DATE)
		SET @RetailYearStart = CASE WHEN MONTH(@beginDate) <> 1 THEN
			CASE WHEN DATEPART(DW, @StartYearFeb1) <=4 THEN DATEADD(WEEK, DATEDIFF(WEEK, 0, @StartYearFeb1), 0)-1 ELSE DATEADD(WEEK, DATEDIFF(WEEK, 0, @StartYearFeb1), 0)+6 END
	   ELSE CASE WHEN DATEPART(DW, DATEADD(year,-1,@StartYearFeb1)) <=4 THEN DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(year,-1,@StartYearFeb1)), 0)-1 ELSE DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(year,-1,@StartYearFeb1)), 0)+6 END
	   END
	   SET @DateNumber=1
		DELETE FROM @DATES_TABLE


	END
END ;

WITH               cte2 ( TheDate, FiscalDate, YearStartDate, RetailWeek, RetailYear, ISOYearStart, ISOYearEnd, ManufacturingYearStart )
                  AS ( SELECT   TheDate ,
                                FiscalDate ,
                                YearStartDate ,
								RetailWeek,
								RetailYear,
                                CASE WHEN DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(YY, 1,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0))))
                                                    / 7 ) * 7, -53690) <= TheDate
                                     THEN DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(YY, 1,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0))))
                                                    / 7 ) * 7, -53690)
                                     WHEN DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0)))
                                                    / 7 ) * 7, -53690) <= TheDate
                                     THEN DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0)))
                                                    / 7 ) * 7, -53690)
                                     ELSE DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(YY, -1,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0))))
                                                    / 7 ) * 7, -53690)
                                END AS ISOYearStart ,
                                CASE WHEN DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(YY, 1,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0))))
                                                    / 7 ) * 7, -53690) <= TheDate
                                     THEN DATEADD(DAY, -1,
                                                  DATEADD(YEAR, 1,
                                                          DATEADD(DD,
                                                              ( DATEDIFF(DD,
                                                              -53690,
                                                              DATEADD(YY, 1,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0))))
                                                              / 7 ) * 7,
                                                              -53690)))
                                     WHEN DATEADD(DD,
                                                  ( DATEDIFF(DD, -53690,
                                                             DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0)))
                                                    / 7 ) * 7, -53690) <= TheDate
                                     THEN DATEADD(DAY, -1,
                                                  DATEADD(DD,
                                                          ( DATEDIFF(DD,
                                                              -53690,
                                                              DATEADD(YY, 1,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0))))
                                                            / 7 ) * 7, -53690))
                                     ELSE DATEADD(DAY, -1,
                                                  DATEADD(DD,
                                                          ( DATEDIFF(DD,
                                                              -53690,
                                                              DATEADD(DD, 3,
                                                              DATEADD(YY,
                                                              DATEDIFF(YY, 0,
                                                              TheDate), 0)))
                                                            / 7 ) * 7, -53690))
                                END AS ISOYearEnd ,
		-- There will be cases where the ManufacturingYearStart won't be correct - typically at the beginning of the year
		-- Don't worry about that here, we'll handle it later in the query
                                CASE WHEN DATEPART(dw,
                                                   DATEADD(YEAR,
                                                           DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              TheDate),
                                                           YearStartDate)) = @WeekStartDay
                                     THEN DATEADD(YEAR,
                                                  DATEDIFF(YEAR, YearStartDate,
                                                           TheDate),
                                                  YearStartDate)
                                     WHEN DATEPART(dw,
                                                   DATEADD(YEAR,
                                                           DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              TheDate),
                                                           YearStartDate)) < @WeekStartDay
                                     THEN DATEADD(d,
                                                  @WeekStartDay - DATEPART(dw,
                                                              DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              TheDate),
                                                              YearStartDate)),
                                                  DATEADD(YEAR,
                                                          DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              TheDate),
                                                          YearStartDate))
                                     ELSE DATEADD(d,
                                                  @WeekStartDay - DATEPART(dw,
                                                              DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              TheDate),
                                                              YearStartDate))
                                                  + 7,
                                                  DATEADD(YEAR,
                                                          DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              TheDate),
                                                          YearStartDate))
                                END
                       FROM     @RetailDatesTable
                     ),
                cte3 ( TheDate, FiscalDate, YearStartDate, RetailWeek, RetailYear, ISOYearStart, ISOYearEnd, ManufacturingYearStart, AdjustedManufacturingYearStart, YearNumber )
                  AS ( SELECT   TheDate ,
                                FiscalDate ,
                                YearStartDate ,
								RetailWeek,
								RetailYear,
                                ISOYearStart ,
                                ISOYearEnd ,
                                ManufacturingYearStart ,
                                CASE WHEN DATEDIFF(d, ManufacturingYearStart,
                                                   TheDate) < 0
                                     THEN CASE WHEN DATEPART(dw,
                                                             DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                              YearStartDate)) = @WeekStartDay
                                               THEN DATEADD(YEAR,
                                                            DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                            YearStartDate)
                                               WHEN DATEPART(dw,
                                                             DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                              YearStartDate)) < @WeekStartDay
                                               THEN DATEADD(d,
                                                            @WeekStartDay
                                                            - DATEPART(dw,
                                                              DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                              YearStartDate)),
                                                            DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                              YearStartDate))
                                               ELSE DATEADD(d,
                                                            @WeekStartDay
                                                            - DATEPART(dw,
                                                              DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                              YearStartDate))
                                                            + 7,
                                                            DATEADD(YEAR,
                                                              DATEDIFF(YEAR,
                                                              YearStartDate,
                                                              DATEADD(DAY, -7,
                                                              TheDate)),
                                                              YearStartDate))
                                          END
                                     ELSE ManufacturingYearStart
                                END ,
                                YEAR(TheDate)
                       FROM     cte2
                     ),

--This cte contains all holidays.  New holidays can be added using a UNION
                holidays ( holidayName, holidayYear, holidayDate )
                  AS ( SELECT   'New Years' AS Holiday ,
                                YearNumber AS [Year] ,
                                TheDate AS [Date]
                       FROM     cte3
                       WHERE    DAY(TheDate) = 1
                                AND MONTH(TheDate) = 1
                       UNION
                       SELECT   'New Years (Observed)' AS Holiday ,
                                YearNumber AS [Year] ,
                                CASE WHEN DATEPART(DW, TheDate) = 1
                                     THEN DATEADD(DAY, 1, TheDate)
                                     WHEN DATEPART(DW, TheDate) = 7
                                     THEN DATEADD(DAY, -1, TheDate)
                                     ELSE TheDate
                                END AS [Date]
                       FROM     cte3
                       WHERE    DAY(TheDate) = 1
                                AND MONTH(TheDate) = 1
                                AND DATEPART(DW, TheDate) IN ( 1, 7 )
                       UNION
-- Martin Luther King Day: Third Monday in January:
                       SELECT   'Martin Luther King Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 1
                                AND DATEPART(DW, TheDate) = 2
                                AND DAY(TheDate) < 22
                       GROUP BY YearNumber
                       UNION

-- Valentine's Day
                       SELECT   'Valentines Day' ,
                                YearNumber ,
                                TheDate
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 2
                                AND DAY(TheDate) = 14
                       UNION
-- President's Day: Third Monday in February
                       SELECT   'Presidents Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 2
                                AND DATEPART(DW, TheDate) = 2
                                AND DAY(TheDate) > 14 AND DAY(TheDate) <22
                       GROUP BY YearNumber
                       UNION
-- St Patricks Day
                       SELECT   'St Patricks Day' ,
                                YearNumber ,
                                TheDate
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 3
                                AND DAY(TheDate) = 17
                       UNION
-- Mother's Day: Second Sunday in May
                       SELECT   'Mothers Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 5
                                AND DATEPART(DW, TheDate) = 1
                                AND DAY(TheDate) > 7 AND DAY(TheDate) <15
                       GROUP BY YearNumber
                       UNION
-- Memorial Day: Last Monday in May: (MAX) WHERE dw = 2
                       SELECT   'Memorial Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 5
                                AND DATEPART(DW, TheDate) = 2
                       GROUP BY YearNumber
                       UNION
-- Father's Day: Third Sunday in May
                       SELECT   'Fathers Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 6
                                AND DATEPART(DW, TheDate) = 1
                                AND DAY(TheDate) > 14 AND DAY(TheDate) <22
                       GROUP BY YearNumber
                       UNION
--Fourth of July
                       SELECT   'Fourth Of July' ,
                                YearNumber ,
                                TheDate
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 7
                                AND DAY(TheDate) = 4
                       UNION
                       SELECT   'Fourth Of July (Observed)' ,
                                YearNumber ,
                                CASE WHEN DATEPART(DW, TheDate) = 1
                                     THEN DATEADD(DAY, 1, TheDate)
                                     WHEN DATEPART(DW, TheDate) = 7
                                     THEN DATEADD(DAY, -1, TheDate)
                                     ELSE TheDate
                                END
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 7
                                AND DAY(TheDate) = 4
                                AND DATEPART(DW, TheDate) IN ( 1, 7 )
                       UNION
-- Labor Day: First Monday in September: MIN WHERE dw = 2
                       SELECT   'Labor Day' ,
                                YearNumber ,
                                MIN(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 9
                                AND DATEPART(DW, TheDate) = 2
                       GROUP BY YearNumber
                       UNION
-- Columbus/Indigenous People's Day: Second Monday in October
                       SELECT   'Columbus/Indigenous Peoples Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 10
                                AND DATEPART(DW, TheDate) = 2
                                AND DAY(TheDate) > 7 AND DAY(TheDate) <15
                       GROUP BY YearNumber
                       UNION
--Halloween
                       SELECT   'Halloween' ,
                                YearNumber ,
                                TheDate
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 10
                                AND DAY(TheDate) = 31
                       UNION
-- US Election Day: "The Tuesday next after the first Monday in November"
                       SELECT   'US Election Day' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 11
                                AND DATEPART(DW, TheDate) = 3
                                AND DAY(TheDate) > 1 AND DAY(TheDate) <9
                       GROUP BY YearNumber
                       UNION
--Veteran's Day
                       SELECT   'Veterans Day' ,
                                YearNumber ,
                                TheDate
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 11
                                AND DAY(TheDate) = 11
                       UNION
-- Thanksgiving: Fourth Thursday in November: MAX WHERE dw = 5 and day_int < 29
                       SELECT   'Thanksgiving' ,
                                YearNumber ,
                                MAX(TheDate)
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 11
                                AND DATEPART(DW, TheDate) = 5
                                AND DAY(TheDate) < 29
                       GROUP BY YearNumber
                       UNION
                       SELECT   'Christmas' ,
                                YearNumber ,
                                TheDate
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 12
                                AND DAY(TheDate) = 25
                       UNION
                       SELECT   'Christmas (Observed)' ,
                                YearNumber ,
                                CASE WHEN DATEPART(DW, TheDate) = 1
                                     THEN DATEADD(DAY, 1, TheDate)
                                     WHEN DATEPART(DW, TheDate) = 7
                                     THEN DATEADD(DAY, -1, TheDate)
                                     ELSE TheDate
                                END
                       FROM     cte3
                       WHERE    MONTH(TheDate) = 12
                                AND DAY(TheDate) = 25
                                AND DATEPART(DW, TheDate) IN ( 1, 7 )
                       UNION
                       SELECT   'Easter' ,
                                YearNumber ,
                                CONVERT(DATE, ( SELECT  RIGHT('0'
                                                              + CONVERT(VARCHAR(2), ( 3
                                                              + ( ( ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              - ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              - 7
                                                              * ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              / 7 ) ) ) + 40 )
                                                              / 44 )), 2)
                                                        + '/' + RIGHT('0'
                                                              + CONVERT(VARCHAR(2), ( ( ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              - ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              - 7
                                                              * ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              / 7 ) ) ) + 28
                                                              - 31 * ( ( 3
                                                              + ( ( ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              - ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              - 7
                                                              * ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              / 7 ) ) ) + 40 )
                                                              / 44 ) / 4 ) )),
                                                              2) + '/'
                                                        + CONVERT(VARCHAR(4), YearNumber)
                                              ))
                       FROM     cte3
                       GROUP BY YearNumber
                       UNION
                       SELECT   'Good Friday' ,
                                YearNumber ,
                                DATEADD(DAY, -2,
                                        CONVERT(DATE, ( SELECT
                                                              RIGHT('0'
                                                              + CONVERT(VARCHAR(2), ( 3
                                                              + ( ( ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              - ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              - 7
                                                              * ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              / 7 ) ) ) + 40 )
                                                              / 44 )), 2)
                                                              + '/'
                                                              + RIGHT('0'
                                                              + CONVERT(VARCHAR(2), ( ( ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              - ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              - 7
                                                              * ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              / 7 ) ) ) + 28
                                                              - 31 * ( ( 3
                                                              + ( ( ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              - ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              - 7
                                                              * ( ( YearNumber
                                                              + YearNumber / 4
                                                              + ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) )
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 1
                                                              - ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) / 28 )
                                                              * ( 29
                                                              / ( ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              - 30
                                                              * ( ( ( (YearNumber
                                                              / 100) )
                                                              - ( (YearNumber
                                                              / 100) ) / 4
                                                              - ( ( (YearNumber
                                                              / 100) )
                                                              - ( ( ( (YearNumber
                                                              / 100) ) - 17 )
                                                              / 25 ) ) / 3
                                                              + 19
                                                              * ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) + 15 )
                                                              / 30 ) ) + 1 ) )
                                                              * ( ( 21
                                                              - ( YearNumber
                                                              - 19
                                                              * ( YearNumber
                                                              / 19 ) ) ) / 11 ) ) )
                                                              + 2
                                                              - ( (YearNumber
                                                              / 100) )
                                                              + ( (YearNumber
                                                              / 100) ) / 4 )
                                                              / 7 ) ) ) + 40 )
                                                              / 44 ) / 4 ) )),
                                                              2) + '/'
                                                              + CONVERT(VARCHAR(4), YearNumber)
                                                      )))
                       FROM     cte3
                       GROUP BY YearNumber
                     ),
---- The cte below it to match holidays (and assiciated buying time) with the holiday of the previous year.  This establishes Comparison Dates
						 HolidaysComp1 (holidayName,TYHolidayMatchDate,CompDate,DayCount) AS
					 (
					 ----Every Holiday on the above calendar will be matched to the holiday the previous year
						SELECT  ha.holidayName, ha.holidayDate AS TYHolidayMatchDate, hb.holidayDate AS CompDate,0
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
					---- Holidays below match the day before.  You can add additional holidays (or remove them) to the IN() statement if there are sales initiatives associated with the day prior to another holiday
						UNION
						SELECT  ha.holidayName, DATEADD(day,-1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-1,hb.holidayDate) AS CompDate,1
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Columbus/Indigenous Peoples Day','Easter','Fathers Day','Halloween','Labor Day','Martin Luther King Day','Memorial Day','Mothers Day','Presidents Day','Fourth Of July','New Years','St Patricks Day','Thanksgiving','Valentines Day')
					----Holiday Matches two days before.  With the exception of Christmas, Easter, and Halloween, this lines up on weekends. You can add additional holidays (or remove them) to the IN() statement if there are sales initiatives associated with the day prior to another holiday
						UNION
						SELECT  ha.holidayName, DATEADD(day,-2,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-2,hb.holidayDate) AS CompDate,2
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Columbus/Indigenous Peoples Day','Easter','Fathers Day','Halloween','Labor Day','Martin Luther King Day','Memorial Day','Mothers Day','Presidents Day','Thanksgiving')

						UNION
						SELECT  ha.holidayName, DATEADD(day,-3,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-3,hb.holidayDate) AS CompDate,3
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Easter','Thanksgiving')

						UNION
						SELECT  ha.holidayName, DATEADD(day,-4,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-4,hb.holidayDate) AS CompDate,4
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Easter','Thanksgiving')

						UNION
						SELECT  ha.holidayName, DATEADD(day,-5,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-5,hb.holidayDate) AS CompDate,5
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Easter','Thanksgiving')

						UNION
						SELECT  ha.holidayName, DATEADD(day,-6,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-6,hb.holidayDate) AS CompDate,6
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Easter')

						UNION
						SELECT  ha.holidayName, DATEADD(day,-7,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,-7,hb.holidayDate) AS CompDate,7
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName IN('Christmas','Easter')

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,1,hb.holidayDate) AS CompDate,0 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,2,hb.holidayDate) AS CompDate,2
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,3,hb.holidayDate) AS CompDate,3 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,4,hb.holidayDate) AS CompDate,4 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,5,hb.holidayDate) AS CompDate,5 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,6,hb.holidayDate) AS CompDate,6 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,7,hb.holidayDate) AS CompDate,7 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,8,hb.holidayDate) AS CompDate,8 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,9,hb.holidayDate) AS CompDate,9 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'

						UNION
						SELECT  ha.holidayName, DATEADD(day,1,ha.holidayDate) AS TYHolidayMatchDate, DATEADD(day,10,hb.holidayDate) AS CompDate,10 --This is Black Friday
						FROM holidays ha
						LEFT JOIN holidays hb ON hb.holidayName=ha.holidayName AND ha.holidayYear = hb.holidayYear +1
						WHERE ha.holidayName ='Thanksgiving'
					 ),
					 ---The below handles when multiple holiday comps land on the same day.  The logic takes the date that is closest to a holiday to conisder for comp date
					 HolidaysComp (holidayName,TYHolidayMatchDate,CompDate) AS(
						SELECT holidayName,hc1.TYHolidayMatchDate,CompDate
						FROM HolidaysComp1 hc1
						JOIN (SELECT TYHolidayMatchDate, MIN(DayCount) MinDay FROM HolidaysComp1 GROUP BY TYHolidayMatchDate ) hcm ON hc1.TYHolidayMatchDate = hcm.TYHolidayMatchDate AND hcm.MinDay = hc1.DayCount
						),
						RetailWeeksInYear (RetailYear,Weeks) AS(
						SELECT
						RetailYear,
						MAX(RetailWeek) AS Weeks
						FROM cte3
						GROUP BY RetailYear
						),
					 cte4(TheDate, FiscalDate, YearStartDate, RetailWeek, RetailYear, ISOYearStart, ISOYearEnd, ManufacturingYearStart, AdjustedManufacturingYearStart, YearNumber, CompDate) AS(
					 SELECT a1.TheDate, a1.FiscalDate, a1.YearStartDate, a1.RetailWeek, a1.RetailYear, a1.ISOYearStart, a1.ISOYearEnd, a1.ManufacturingYearStart, a1.AdjustedManufacturingYearStart, a1.YearNumber, COALESCE(hc.CompDate,CASE WHEN wy.Weeks !=53 THEN b.TheDate ELSE DATEADD(week,1,b.TheDate) END) CompDate 
					 FROM cte3 a1
					 LEFT OUTER JOIN holidays h ON a1.TheDate = h.holidayDate
					 LEFT JOIN RetailWeeksInYear wy ON wy.RetailYear = a1.RetailYear-1
					 LEFT JOIN cte3 b ON CASE WHEN a1.RetailWeek != 53 THEN a1.RetailWeek ELSE 1 END = b.RetailWeek AND CASE WHEN a1.RetailWeek != 53 THEN a1.RetailYear ELSE a1.RetailYear +1 END =b.RetailYear+1 AND DATEPART(DW, a1.TheDate)=DATEPART(DW, b.TheDate)
					 LEFT JOIN HolidaysComp hc ON hc.TYHolidayMatchDate = a1.TheDate
					 ),


-----This is the final selection table
                ret ( [DateId], [Date], [DateShortName], [DateLongName], [JulianDate], [JulianDateModified], [YearKey], [YearName], [YearStartDate], [YearEndDate], [YearSeqNo], [YearQuarterKey], [YearQuarterName], [QuarterOfYearKey], [QuarterOfYearName], [YearQuarterStartDate], [YearQuarterEndDate], [YearQuarterSeqNo], [YearMonthKey], [YearMonthShortName], [YearMonthLongName], [MonthOfYearKey], [MonthOfYearShortName], [MonthOfYearLongName], [YearMonthStartDate], [YearMonthEndDate], [YearMonthSeqNo], [YearWeekKey], [YearWeekShortName], [YearWeekLongName], [YearWeekStartDate], [YearWeekEndDate], [YearWeekSeqNo], [WeekOfYearKey], [WeekOfYearShortName], [WeekOfYearLongName], [YearDOYKey], [YearDOYShortName], [YearDOYLongName], [DayOfYearKey], [DayOfYearName], [DayOfMonthKey], [DayOfMonthName], [DayOfWeekKey], [DayOfWeekName], [FiscalYearKey], [FiscalYearName], [FiscalYearStartDate], [FiscalYearEndDate], [FiscalYearSeqNo], [FiscalYearQuarterKey], [FiscalYearQuarterName], [FiscalQuarterOfYearKey], [FiscalQuarterOfYearName], [FiscalYearQuarterStartDate], [FiscalYearQuarterEndDate], [FiscalYearQuarterSeqNo], [FiscalYearMonthKey], [FiscalYearMonthShortName], [FiscalYearMonthLongName], [FiscalMonthOfYearKey], [FiscalMonthOfYearShortName], [FiscalMonthOfYearLongName], [FiscalYearMonthStartDate], [FiscalYearMonthEndDate], [FiscalYearMonthSeqNo], [FiscalYearWeekKey], [FiscalYearWeekShortName], [FiscalYearWeekLongName], [FiscalYearWeekSeqNo], [FiscalYearDOYKey], [FiscalYearDOYShortName], [FiscalYearDOYLongName], [FiscalDayOfYearKey], [FiscalDayOfYearName], [FiscalDayOfMonthKey], [FiscalDayOfMonthName], [FiscalDayOfWeekKey], [FiscalDayOfWeekName], [RetailWeek],[RetailYear]
						, [IsWeekend], [IsHoliday], [HolidayName], [IsLeapYear], [CompDate], [CompDateID] )
                  AS ( SELECT   DateId = CONVERT(INT, CONVERT(VARCHAR(8), TheDate, 112)) ,
                                [Date] = TheDate ,
                                [DateShortName] = CONVERT(VARCHAR(10), TheDate, 120) ,
                                [DateLongName] = DATENAME(DW, TheDate) + ', '
                                + DATENAME(MONTH, TheDate) + ' '
                                + DATENAME(DAY, TheDate) + ', '
                                + DATENAME(YEAR, TheDate) ,
                                [JulianDate] = DATEDIFF(DAY,
                                                        @EarliestPossibleDate,
                                                        TheDate) + 2361331 ,
                                [JulianDateModified] = DATEDIFF(DAY,
                                                              @ModifiedJulianDateStart,
                                                              TheDate) ,
                                [YearKey] = DATEPART(YEAR, TheDate) ,
                                [YearName] = DATENAME(YEAR, TheDate) ,
                                [YearStartDate] = CONVERT(DATE, DATEADD(YEAR,
                                                              DATEDIFF(YEAR, 0,
                                                              TheDate), 0)) ,
                                [YearEndDate] = CONVERT(DATE, DATEADD(DAY, -1,
                                                              DATEADD(YEAR,
                                                              DATEDIFF(YEAR, 0,
                                                              TheDate) + 1, 0))) ,
                                [YearSeqNo] = DATEDIFF(YEAR,
                                                       @EarliestPossibleDate,
                                                       TheDate) ,
                                [YearQuarterKey] = CONVERT(INT, DATENAME(YEAR,
                                                              TheDate)
                                + DATENAME(QUARTER, TheDate)) ,
                                [YearQuarterName] = 'Q' + DATENAME(QUARTER,
                                                              TheDate) + ' '
                                + DATENAME(YEAR, TheDate) ,
                                [QuarterOfYearKey] = CONVERT(INT, '4'
                                + DATENAME(QUARTER, TheDate)) ,
                                [QuarterOfYearName] = 'Q' + DATENAME(QUARTER,
                                                              TheDate) ,
                                [YearQuarterStartDate] = CONVERT(DATE, DATEADD(QUARTER,
                                                              DATEDIFF(QUARTER,
                                                              0, TheDate), 0)) ,
                                [YearQuarterEndDate] = CONVERT(DATE, DATEADD(DAY,
                                                              -1,
                                                              DATEADD(QUARTER,
                                                              DATEDIFF(QUARTER,
                                                              0, TheDate) + 1,
                                                              0))) ,
                                [YearQuarterSeqNo] = DATEDIFF(QUARTER,
                                                              @EarliestPossibleDate,
                                                              TheDate) ,
                                [YearMonthKey] = CONVERT(INT, CONVERT(VARCHAR(6), TheDate, 112)) ,
                                [YearMonthShortName] = RIGHT(CONVERT(VARCHAR(11), TheDate, 106),
                                                             8) ,
                                [YearMonthLongName] = DATENAME(MONTH, TheDate)
                                + ' ' + DATENAME(YEAR, TheDate) ,
                                [MonthOfYearKey] = CONVERT(INT, '12'
                                + RIGHT('00'
                                        + CONVERT(VARCHAR(2), MONTH(TheDate)),
                                        2)) ,
                                [MonthOfYearShortName] = LEFT(DATENAME(MONTH,
                                                              TheDate), 3) ,
                                [MonthOfYearLongName] = DATENAME(MONTH,
                                                              TheDate) ,
                                [YearMonthStartDate] = CONVERT(DATE, DATEADD(MONTH,
                                                              DATEDIFF(MONTH,
                                                              0, TheDate), 0)) ,
                                [YearMonthEndDate] = CONVERT(DATE, DATEADD(DAY,
                                                              -1,
                                                              DATEADD(MONTH,
                                                              DATEDIFF(MONTH,
                                                              0, TheDate) + 1,
                                                              0))) ,
                                [YearMonthSeqNo] = DATEDIFF(MONTH,
                                                            @EarliestPossibleDate,
                                                            TheDate) ,
                                [YearWeekKey] = CONVERT(INT, DATENAME(YEAR,
                                                              TheDate) + '52'
                                + RIGHT('00'
                                        + CONVERT(VARCHAR(2), DATEPART(WEEK,
                                                              TheDate)), 2)) ,
                                [YearWeekShortName] = 'W' + DATENAME(WEEK,
                                                              TheDate) + ' '
                                + DATENAME(YEAR, TheDate) ,
                                [YearWeekLongName] = 'Week ' + DATENAME(WEEK,
                                                              TheDate) + ', '
                                + DATENAME(YEAR, TheDate) ,
                                [YearWeekStartDate] = CONVERT(DATE, DATEADD(DAY,
                                                              -1,
                                                              DATEADD(WEEK,
                                                              DATEDIFF(WEEK, 0,
                                                              TheDate), 0))) ,
                                [YearWeekEndDate] = CONVERT(DATE, DATEADD(DAY,
                                                              -2,
                                                              DATEADD(WEEK,
                                                              DATEDIFF(WEEK, 0,
                                                              TheDate) + 1, 0))) ,
                                [YearWeekSeqNo] = DATEDIFF(WEEK,
                                                           @EarliestPossibleDate,
                                                           TheDate) ,
                                [WeekOfYearKey] = CONVERT(INT, '5252'
                                + RIGHT('00'
                                        + CONVERT(VARCHAR(2), DATEPART(WEEK,
                                                              TheDate)), 2)) ,
                                [WeekOfYearShortName] = 'W' + DATENAME(WEEK,
                                                              TheDate) ,
                                [WeekOfYearLongName] = 'Week ' + DATENAME(WEEK,
                                                              TheDate) ,
                                [YearDOYKey] = CONVERT(INT, DATENAME(YEAR,
                                                              TheDate)
                                + RIGHT('000'
                                        + CONVERT(VARCHAR(3), DATEPART(DAYOFYEAR,
                                                              TheDate)), 3)) ,
                                [YearDOYShortName] = 'D' + DATENAME(DAYOFYEAR,
                                                              TheDate) + ' '
                                + DATENAME(YEAR, TheDate) ,
                                [YearDOYLongName] = 'Day '
                                + DATENAME(DAYOFYEAR, TheDate) + ', '
                                + DATENAME(YEAR, TheDate) ,
                                [DayOfYearKey] = CONVERT(INT, '365'
                                + RIGHT('000'
                                        + CONVERT(VARCHAR(3), DATEPART(DAYOFYEAR,
                                                              TheDate)), 3)) ,
                                [DayOfYearName] = 'Day ' + DATENAME(DAYOFYEAR,
                                                              TheDate) ,
                                [DayOfMonthKey] = CONVERT(INT, '31'
                                + RIGHT('00' + DATENAME(DAY, TheDate), 2)) ,
                                [DayOfMonthName] = 'Day ' + DATENAME(DAY,
                                                              TheDate) ,
                                [DayOfWeekKey] = CONVERT(INT, '7'
                                + CONVERT(VARCHAR(1), DATEPART(DW, TheDate))) ,
                                [DayOfWeekName] = DATENAME(DW, TheDate) ,
                                [FiscalYearKey] = DATEPART(YEAR, FiscalDate) ,
                                [FiscalYearName] = 'FY' + DATENAME(YEAR,
                                                              FiscalDate) ,
                                [FiscalYearStartDate] = DATEADD(MONTH,
                                                              @FiscalYearOffsetInMonths,
                                                              CONVERT(DATE, DATENAME(YEAR,
                                                              FiscalDate))) ,
                                [FiscalYearEndDate] = DATEADD(DAY, -1,
                                                              DATEADD(YEAR, 1,
                                                              DATEADD(MONTH,
                                                              @FiscalYearOffsetInMonths,
                                                              CONVERT(DATE, DATENAME(YEAR,
                                                              FiscalDate))))) ,
                                [FiscalYearSeqNo] = DATEDIFF(YEAR,
                                                             @EarliestPossibleDate,
                                                             TheDate) ,
                                [FiscalYearQuarterKey] = CONVERT(INT, DATENAME(YEAR,
                                                              FiscalDate)
                                + DATENAME(QUARTER, FiscalDate)) ,
                                [FiscalYearQuarterName] = 'Q'
                                + DATENAME(QUARTER, FiscalDate) + ' FY'
                                + DATENAME(YEAR, FiscalDate) ,
                                [FiscalQuarterOfYearKey] = CONVERT(INT, '4'
                                + DATENAME(QUARTER, FiscalDate)) ,
                                [FiscalQuarterOfYearName] = 'FYQ'
                                + DATENAME(QUARTER, FiscalDate) ,
                                [FiscalYearQuarterStartDate] = CONVERT(DATE, DATEADD(QUARTER,
                                                              DATEDIFF(QUARTER,
                                                              0, TheDate), 0)) ,
                                [FiscalYearQuarterEndDate] = CONVERT(DATE, DATEADD(DAY,
                                                              -1,
                                                              DATEADD(QUARTER,
                                                              DATEDIFF(QUARTER,
                                                              0, TheDate) + 1,
                                                              0))) ,
                                [FiscalYearQuarterSeqNo] = DATEDIFF(QUARTER,
                                                              @EarliestPossibleDate,
                                                              TheDate) ,
                                [FiscalYearMonthKey] = CONVERT(INT, DATENAME(YEAR,
                                                              FiscalDate)
                                + RIGHT('00'
                                        + CONVERT(VARCHAR(2), DATEPART(MONTH,
                                                              FiscalDate)), 2)) ,
                                [FiscalYearMonthShortName] = LEFT(DATENAME(MONTH,
                                                              TheDate), 3)
                                + ' FY' + DATENAME(YEAR, FiscalDate) ,
                                [FiscalYearMonthLongName] = DATENAME(MONTH,
                                                              TheDate) + ' FY'
                                + DATENAME(YEAR, FiscalDate) ,
                                [FiscalMonthOfYearKey] = CONVERT(INT, '12'
                                + RIGHT('00'
                                        + CONVERT(VARCHAR(2), DATEPART(MONTH,
                                                              FiscalDate)), 2)) ,
                                [FiscalMonthOfYearShortName] = LEFT(DATENAME(MONTH,
                                                              TheDate), 3) ,
                                [FiscalMonthOfYearLongName] = DATENAME(MONTH,
                                                              TheDate) ,
                                [FiscalYearMonthStartDate] = CONVERT(DATE, DATEADD(MONTH,
                                                              DATEDIFF(MONTH,
                                                              0, TheDate), 0)) ,
                                [FiscalYearMonthEndDate] = CONVERT(DATE, DATEADD(DAY,
                                                              -1,
                                                              DATEADD(MONTH,
                                                              DATEDIFF(MONTH,
                                                              0, TheDate) + 1,
                                                              0))) ,
                                [FiscalYearMonthSeqNo] = DATEDIFF(MONTH,
                                                              @EarliestPossibleDate,
                                                              TheDate) ,
                                [FiscalYearWeekKey] = CONVERT(INT, DATENAME(YEAR,
                                                              FiscalDate)
                                + '52' + RIGHT('00'
                                               + CONVERT(VARCHAR(2), DATEPART(WEEK,
                                                              FiscalDate)), 2)) ,
                                [FiscalYearWeekShortName] = 'W'
                                + DATENAME(WEEK, FiscalDate) + ' FY'
                                + DATENAME(YEAR, FiscalDate) ,
                                [FiscalYearWeekLongName] = 'Week '
                                + DATENAME(WEEK, FiscalDate) + ', FY'
                                + DATENAME(YEAR, FiscalDate) ,
                                [FiscalYearWeekSeqNo] = DATEDIFF(WEEK,
                                                              @EarliestPossibleDate,
                                                              TheDate) ,
                                [FiscalYearDOYKey] = CONVERT(INT, DATENAME(YEAR,
                                                              FiscalDate)
                                + '365' + RIGHT('000'
                                                + CONVERT(VARCHAR(3), DATEPART(DAYOFYEAR,
                                                              FiscalDate)), 3)) ,
                                [FiscalYearDOYShortName] = 'D'
                                + DATENAME(DAYOFYEAR, FiscalDate) + ' FY'
                                + DATENAME(YEAR, FiscalDate) ,
                                [FiscalYearDOYLongName] = 'Day '
                                + DATENAME(DAYOFYEAR, FiscalDate) + ', FY'
                                + DATENAME(YEAR, FiscalDate) ,
                                [FiscalDayOfYearKey] = CONVERT(INT, '365'
                                + RIGHT('000'
                                        + CONVERT(VARCHAR(3), DATEPART(DAYOFYEAR,
                                                              FiscalDate)), 3)) ,
                                [FiscalDayOfYearName] = 'Day '
                                + DATENAME(DAYOFYEAR, FiscalDate) ,
                                [FiscalDayOfMonthKey] = CONVERT(INT, '31'
                                + RIGHT('00' + DATENAME(DAY, TheDate), 2)) ,
                                [FiscalDayOfMonthName] = 'Day ' + DATENAME(DAY,
                                                              TheDate) ,
                                [FiscalDayOfWeekKey] = CONVERT(INT, '7'
                                + CONVERT(VARCHAR(1), DATEPART(DW, TheDate))) ,
                                [FiscalDayOfWeekName] = DATENAME(DW, TheDate),
								[RetailWeek] = RetailWeek,
								[RetailYear] = RetailYear,
                                IsWeekend = CASE WHEN DATEPART(DW, TheDate) IN (
                                                      1, 7 ) THEN 1
                                                 ELSE 0
                                            END ,
                                IsHoliday = CASE WHEN h.holidayDate IS NOT NULL
                                                 THEN 1
                                                 ELSE 0
                                            END ,
                                holidayName = h.holidayName ,
                                IsLeapYear = CASE WHEN ( DATEPART(YEAR,
                                                              TheDate) % 4 = 0
                                                         AND DATEPART(YEAR,
                                                              TheDate) % 100 <> 0
                                                       )
                                                       OR DATEPART(YEAR,
                                                              TheDate) % 400 = 0
                                                  THEN 1
                                                  ELSE 0
                                             END,
											 CompDate = CompDate,
											 CompDateID = CONVERT(INT, CONVERT(VARCHAR(8), CompDate, 112))
                       FROM     cte4 a
                       LEFT OUTER JOIN holidays h ON a.TheDate = h.holidayDate 
                     )
            INSERT  INTO @ret
                    ( [DimDateID] ,
                      [Date] ,
                      [DateShortName] ,
                      [DateLongName] ,
                      [JulianDate] ,
                      [JulianDateModified] ,
                      [YearKey] ,
                      [YearName] ,
                      [YearStartDate] ,
                      [YearEndDate] ,
                      [YearSeqNo] ,
                      [YearQuarterKey] ,
                      [YearQuarterName] ,
                      [QuarterOfYearKey] ,
                      [QuarterOfYearName] ,
                      [YearQuarterStartDate] ,
                      [YearQuarterEndDate] ,
                      [YearQuarterSeqNo] ,
                      [YearMonthKey] ,
                      [YearMonthShortName] ,
                      [YearMonthLongName] ,
                      [MonthOfYearKey] ,
                      [MonthOfYearShortName] ,
                      [MonthOfYearLongName] ,
                      [YearMonthStartDate] ,
                      [YearMonthEndDate] ,
                      [YearMonthSeqNo] ,
                      [YearWeekKey] ,
                      [YearWeekShortName] ,
                      [YearWeekLongName] ,
                      [YearWeekStartDate] ,
                      [YearWeekEndDate] ,
                      [YearWeekSeqNo] ,
                      [WeekOfYearKey] ,
                      [WeekOfYearShortName] ,
                      [WeekOfYearLongName] ,
                      [YearDOYKey] ,
                      [YearDOYShortName] ,
                      [YearDOYLongName] ,
                      [DayOfYearKey] ,
                      [DayOfYearName] ,
                      [DayOfMonthKey] ,
                      [DayOfMonthName] ,
                      [DayOfWeekKey] ,
                      [DayOfWeekName] ,
					  [RetailWeek],
					  [RetailYear],
                      [IsWeekend] ,
                      [IsHoliday] ,
                      [HolidayName] ,
                      [IsLeapYear],
					  [CompDate],
					  [CompDateID]
                    )
                    SELECT  ret.DateId ,
                            [Date] ,
                            [DateShortName] ,
                            [DateLongName] ,
                            [JulianDate] ,
                            [JulianDateModified] ,
                            [YearKey] ,
                            [YearName] ,
                            [YearStartDate] ,
                            [YearEndDate] ,
                            [YearSeqNo] ,
                            [YearQuarterKey] ,
                            [YearQuarterName] ,
                            [QuarterOfYearKey] ,
                            [QuarterOfYearName] ,
                            [YearQuarterStartDate] ,
                            [YearQuarterEndDate] ,
                            [YearQuarterSeqNo] ,
                            [YearMonthKey] ,
                            [YearMonthShortName] ,
                            [YearMonthLongName] ,
                            [MonthOfYearKey] ,
                            [MonthOfYearShortName] ,
                            [MonthOfYearLongName] ,
                            [YearMonthStartDate] ,
                            [YearMonthEndDate] ,
                            [YearMonthSeqNo] ,
                            [YearWeekKey] ,
                            [YearWeekShortName] ,
                            [YearWeekLongName] ,
                            [YearWeekStartDate] ,
                            [YearWeekEndDate] ,
                            [YearWeekSeqNo] ,
                            [WeekOfYearKey] ,
                            [WeekOfYearShortName] ,
                            [WeekOfYearLongName] ,
                            [YearDOYKey] ,
                            [YearDOYShortName] ,
                            [YearDOYLongName] ,
                            [DayOfYearKey] ,
                            [DayOfYearName] ,
                            [DayOfMonthKey] ,
                            [DayOfMonthName] ,
                            [DayOfWeekKey] ,
                            [DayOfWeekName] ,
							[RetailWeek],
							[RetailYear],
                            [IsWeekend] ,
                            [IsHoliday] ,
                            [HolidayName] ,
                            [IsLeapYear],
							[CompDate],
							[CompDateID]
                    FROM    ret
					WHERE Date >= @originalbegin
            OPTION  ( MAXRECURSION 32767 );



    END;

	SELECT * FROM @ret