Hi,
Teradata has a database called SYS_CALENDAR which contains 1 table
SYS_CALENDAR.CALDATES
with every date between Jan 1, 1900 and Dec 31, 2100. Then it has 3 views for defining stuff like Day_of_week, week_of_year, day_of_year.
CALBASICS
CALENDARTMP
CALENDAR
the only one of use is
SYS_CALENDAR.CALENDAR
since it simplifies the inclusion of the other 2 views to well known column names although all the formulas for calulating everything are hidden inside
SYS_CALENDAR.CALENDARTMP;
you typically do
sel week_of_year from SYS_CALENDAR.CALENDAR
where calendar_date = date;
Your problem is week_of_YEAR is based SUN to Sat and you need Mon to Sunday.
I suspect that you could probably define your own view in your own database which is based upon
sel week_of_year_monday_based
from MYCALENDAR
where calendar_date = date;
or something like that. ( I haven't actually tried the formula above so if it's wrong you will have to create your own to make the correct output. )
If you need some other date value just look at the table and view defintions under SYS_CALENDAR and modify them accordingly.
I won't advise changing the Teradata System views or putting your view inside SYS_CALENDAR database since when you upgrade the upgrade may delete and recreate the whole database and/or views and therefore your modification may be lost.
I am able to get weeks as below :
Date Week DAY
2001-01-01 00 Mon
2001-01-02 00 The
2001-01-03 00 Wen
2001-01-04 01 THU
2001-01-05 01 Fri
Here First week which is the part of last years week.
Is it possible to get like...
Date Week DAY
2001-01-01 52 Mon
2001-01-02 52 The
2001-01-03 52 Wen
2001-01-04 01 THU
2001-01-05 01 Fri
I tried week(date)- 1 but it is not consistence with this calendar....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.