i'm new in this forum.
I have to simple problems that i cannot solve:
- I need to find a function that calculate in Teradata the weekday of a date variabile.
- i need to compare a Time variable whit some constant values:
when var_time < '18:00' then 1
when var_time < '11:00' then 2
Thanks in advance for you help
To find out the weekday of a date, you can use - SYS_CALENDAR.CALENDAR
To compare the time variable with the constant value, you can put the constant value in the quotes as you did in your example with the same format of your time variable.
There's no built-in function for weekday, but besides a calendar you might do a simple calculation, e.g. this will return monday as 1:
REPLACE FUNCTION day_of_week(cdate DATE)
RETURNS NULL ON NULL INPUT
INLINE TYPE 1
RETURN ((cdate - DATE '0001-01-01') MOD 7) + 1
If you can't create SQL UDFs simply use the calculation as-is.
There's only one recommended qway to write a time literal: TIME '18:00:00'
Similar for dates: DATE '2013-07-21' and timestamps: TIMESTAMP '2013-07-21 18:00:00'