17.05 - Example: Using the BEGIN and END Period Bound Functions as Conditions When Merging Into a RPPI Table - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Published
January 2021
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
vnq1596660420420.ditamap
dita:ditavalPath
hoy1596145193032.ditaval

Assume you define the following two tables:

     CREATE SET TABLE testing.t21 (
       a INTEGER,
       b DATE FORMAT 'YY/MM/DD',
       c DATE FORMAT 'YY/MM/DD')
     PRIMARY INDEX (a);

     CREATE SET TABLE testing.t22 (
       a INTEGER,
       b PERIOD (DATE))
     PRIMARY INDEX (a)
     PARTITION BY (CASE_N((END(b))<= DATE '2008-03-31',
                          (END(b))<= DATE '2008-06-30',
                          (END(b))<= DATE '2008-09-30',
                          (END(b))<= DATE '2008-12-31'),
                          CASE_N((BEGIN(b))> DATE '2008-12-31')
                                 (BEGIN(b))> DATE '2008-09-30',
                                 (BEGIN(b))> DATE '2008-06-30',
                                 (BEGIN(b))> DATE '2008-03-31',);

The following MERGE request merges rows from t11 in to t22.

     MERGE INTO t22
       USING t21
       ON t22.a = t21.a
       AND BEGIN(t22.b) = t21.b
       AND END(t22.b) = t21.c
     WHEN MATCHED THEN
       UPDATE SET c=4
     WHEN NOT MATCHED THEN
       INSERT VALUES (t21.a, PERIOD(t21.b, t21.c), 4);