Example of Setting the Value of a Period Type - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™
void set_duration( DATE       *date1,
                   DATE       *date2,
                   PDT_HANDLE *result,
                   int        *date1IsNull,
                   int        *date2IsNull,
                   int        *resultIsNull,
                   char        sqlstate[6])
                   SQL_TEXT    extname[129],
                   SQL_TEXT    specific_name[129],
                   SQL_TEXT    error_message[257] )
{
    DATE new_duration[2];

    /* Set the value of the PERIOD(DATE) result. */
    if (*date2 > *date1)
    {
       new_duration[0] = *date1;
       new_duration[1] = *date2;
    }
    else if (*date1 > *date2)
    {
       new_duration[0] = *date2;
       new_duration[1] = *date1;
    }
    else
    {
       strcpy(sqlstate, "22023");
       strcpy((char *) error_message,
          "PERIOD element values cannot be equal.") ;
       *resultIsNull = -1;
       return;
    }
    FNC_SetInternalValue(*result, &new_duration[0], SIZEOF_DATE*2); 

    ...

}