Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Equivalent function for DATEADD - response (3) by dnoeth

$
0
0

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
 
 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>