DAYOFWEEK is no Teradata syntax, might be a UDF installed at your system. Anyway it's returning the weekday based on sunday as starting day. But you need ISO weeks :-)
What is your TD release?
In TD14.10 there's a built-in function:
TD_WEEK_BEGIN(date, 'ISO')
Before you might use this calculation:
REPLACE FUNCTION WEEK_BEGIN(cdate DATE)
RETURNS DATE
SPECIFIC week_begin_DA
RETURNS NULL ON NULL INPUT
CONTAINS SQL
DETERMINISTIC
COLLATION INVOKER
INLINE TYPE 1
RETURN
cdate-(((cdate - DATE '0001-01-01')) MOD 7);
If you're not on TD13.10 or you can't create SQL-UDFs you can simply use the formula as-is:
APPOINTMENT_START_DATE.BI_ACTIVITY_DATE-(((APPOINTMENT_START_DATE.BI_ACTIVITY_DATE - DATE '0001-01-01')) MOD 7)
Adding 8 weeks is just x + 8*7.
Do you need a BETWEEN week_begin AND week_begin + 8*7 -1 or just the 8 mondays?
Then you might use EXPAND on in TD13.10:
SELECT BEGIN(pd)
FROM sys_calendar.CALENDAR
WHERE calendar_date = DATE
EXPAND ON PERIOD(WEEK_BEGIN(calendar_date), WEEK_BEGIN(calendar_date) + 8*7) AS pd
BY ANCHOR MONDAY
Dieter
DAYOFWEEK is no Teradata syntax, might be a UDF installed at your system. Anyway it's returning the weekday based on sunday as starting day. But you need ISO weeks :-)
What is your TD release?
In TD14.10 there's a built-in function:
TD_WEEK_BEGIN(date, 'ISO')
Before you might use this calculation:
If you're not on TD13.10 or you can't create SQL-UDFs you can simply use the formula as-is:
Adding 8 weeks is just x + 8*7.
Do you need a BETWEEN week_begin AND week_begin + 8*7 -1 or just the 8 mondays?
Then you might use EXPAND on in TD13.10:
Dieter