SEL B.STARTDATE,COALESCE(MAX(STARTDATE) OVER( PARTITION BY 3 ORDER BY STARTDATE ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)-1,STARTDATE+13) AS DW_EXPR_DT
FROM
(SEL A.DD as STARTDATE, RANK() OVER(ORDER BY DD) RN
FROM
(
SEL DISTINCT
CASE WHEN DAYOFWEEK(CALENDAR_DATE) =2 THEN CALENDAR_DATE
ELSE
CASE WHEN CALENDAR_DATE
SEL B.STARTDATE,COALESCE(MAX(STARTDATE) OVER( PARTITION BY 3 ORDER BY STARTDATE ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)-1,STARTDATE+13) AS DW_EXPR_DT
FROM
(SEL A.DD as STARTDATE, RANK() OVER(ORDER BY DD) RN
FROM
(
SEL DISTINCT
CASE WHEN DAYOFWEEK(CALENDAR_DATE) =2 THEN CALENDAR_DATE
ELSE
CASE WHEN CALENDAR_DATE