Example: Using the BEGIN Period Bound Function as a Condition 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.t11 (
       a INTEGER,
       b DATE FORMAT 'YY/MM/DD',
       c DATE FORMAT 'YY/MM/DD')
     PRIMARY INDEX (a);

     CREATE SET TABLE testing.t12 (
       a INTEGER,
       b PERIOD(DATE),
       c INTEGER)
     PRIMARY INDEX (a)
     PARTITION BY RANGE_N((BEGIN(b) BETWEEN DATE '2009-01-01'
                                    AND     DATE '2011-12-31'
                                    EACH INTERVAL '1' MONTH);

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

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