Example: Using the BEGIN and END Period Bound Functions as Conditions When Merging Into a RPPI Table - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

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
2024-04-05
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantage™

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);