Teradata SQL Assist - Datepart Function

General

Teradata SQL Assist - Datepart Function

I need to know how to write the following SQL statement in Teradata SQL Assist:

 CASE WHEN DATEPART(WEEKDAY,GETDATE()) = 2

I know I have to use Current_Date instead of the GETDATE() function.

3 REPLIES
Enthusiast

Re: Teradata SQL Assist - Datepart Function

case when 
(
sel day_of_week from sys_calendar.calendar where calendar_date = current_date) = 2

Rglass

Junior Contributor

Re: Teradata SQL Assist - Datepart Function

When does your week start, Sunday or Monday?

All the sys_calendar colunms are available as functions, too:

 -- week starts on Sunday:
td_day_of_week(current_date)
or
DayNumber_Of_Week(current_date, 'TERADATA')

-- week starts on Monday
DayNumber_Of_Week(current_date, 'ISO')

Re: Teradata SQL Assist - Datepart Function

Thanks Rglass, that's exactly what I needed.

Thank you also Dieter, our workweek starts on Sunday (day 1), but on Mondays (day 2) I use a case statement to look back two days when pulling data as opposed to just looking back one day when the code is ran Tues through Sat.