Example: Inserting the Default Value under Certain Conditions - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Consider the following Employee table definition:

   CREATE TABLE Employee
      (Emp_ID      INTEGER
      ,Last_Name   VARCHAR(30)
      ,First_Name  VARCHAR(30)
      ,Dept_No     INTEGER DEFAULT 99
   );

The following statement uses DEFAULT to insert the default value of the Dept_No column when the supplied value is negative.

   USING (id INTEGER, n1 VARCHAR(30), n2 VARCHAR(30), dept INTEGER)
   INSERT INTO Employee VALUES
      (:id
      ,:n1
      ,:n2
      ,CASE WHEN (:dept < 0) THEN DEFAULT(Dept_No) ELSE :dept END
   );