Week number based on which definition?
This is a SQL function for TD13.10 to calculate it based on the International Standard, i.e. week starts on monday and the first week always includes jan 4.
REPLACE FUNCTION iso_week(cdate DATE)
RETURNS INT
SPECIFIC iso_week_date
RETURNS NULL ON NULL INPUT
CONTAINS SQL
DETERMINISTIC
COLLATION INVOKER
INLINE TYPE 1
RETURN
(((cDate - (((cdate - DATE '0001-01-01') MOD 7) + 1) + 4)
- ((EXTRACT(YEAR FROM (cDate - (((cdate - DATE '0001-01-01') MOD 7) + 1) + 4)) - 1900) * 10000 + 0101 (DATE))) / 7) + 1 (FORMAT '99')
Otherwise you might join to sys_calendar.calendar or check how it's calculating it.
Dieter
↧