NEXT_DAY
Purpose
Returns the date of the first weekday (day_value) that is later than the date specified by date_timestamp_value.
Syntax
where:
Syntax element … |
Specifies … |
TD_SYSFNLIB |
the name of the database where the function is located. |
date_timestamp_value |
a date or timestamp argument. If date_timestamp_value is NULL, NULL is returned. |
day_value |
a character argument. day_value can be any day of the week or its 3 character abbreviation. Valid values are: The day of week is not case sensitive. Any characters that follow a valid abbreviation are ignored. If day_value is NULL, NULL is returned. Note: While all systems are shipped only supporting the above English values for day_value, the Database Administrator can extend valid values to properly handle localized day names by including them in the ShortDays or LongDays of the Specification for Data Formatting (SDF) file supplied to the tdlocaledef utility. |
ANSI Compliance
This is a Teradata extension to the ANSI SQL:2011 standard.
Invocation
NEXT_DAY is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.
Argument Types and Rules
Expressions passed to this function must have the following data types:
You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.
Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.
For details, see “Compatible Types” in SQL External Routine Programming.
Since TIMESTAMP values are stored in UTC time within the database and lack a time zone, the session time zone is used to interpret the time stamp value within the function. For TIMESTAMP WITH TIME ZONE values, the time zone component is used to interpret the time stamp value within the function.
Result Type
The return data type is DATE.
Example
The following query:
SELECT NEXT_DAY(DATE '2009-12-20', 'TUESDAY');
returns the result 09/12/22 since 12/22 is the next Tuesday after Sunday, Dec 20, 2009.
Example
The following query:
SELECT NEXT_DAY(DATE '2009-12-20', 'FRIDAY');
returns the result 09/12/25 since 12/25 is the next Friday after Sunday, Dec 20, 2009.
Example
The following query:
SELECT NEXT_DAY(DATE '2009-12-25', 'FRIDAY');
returns the result 10/01/01 since Jan 1, 2010 is the next Friday after Friday, Dec 25, 2009.
Example
NEXT_DAY (date_timestamp_value, day_value) works with the Specification for Data Formatting. Here is an example of the Japanese tdlocaledef.txt and how NEXT_DAY works with those definitions.
// DBS System Formatting Data
// Day and month names
ShortDays {
"\u65e5";
"\u6708";
"\u706b";
"\u6c34";
"\u6728";
"\u91d1";
"\u571f"
}
LongDays {
"\u65e5\u66dc\u65e5";
"\u6708\u66dc\u65e5";
"\u706b\u66dc\u65e5"; /*
*/
"\u6c34\u66dc\u65e5";
"\u6728\u66dc\u65e5";
"\u91d1\u66dc\u65e5";
"\u571f\u66dc\u65e5"
}
ShortMonths {
"1\u6708";
"2\u6708";
"3\u6708";
"4\u6708";
"5\u6708";
"6\u6708";
"7\u6708";
"8\u6708";
"9\u6708";
"10\u6708";
"11\u6708";
"12\u6708"
}
The following SQL fails with an error:
select next_day(to_date('2015/06/22','YYYY/MM/DD'),'Tue') AS "
";
Instead, use the Japanese day_value defined in the tdlocaledef.txt as follows:
select next_day(to_date('2015/06/22','YYYY/MM/DD'),'
') AS "
";
---------
15/06/23
Note: "\u706b\u66dc\u65e5"; indicates "Tuesday" in Japanese, as demonstrated below.
Sel _UNICODE U&'#706b#66dc#65e5' UESCAPE '#';
'
'
-----------------
