DEFAULT Function Examples | Teradata Vantage - Example: Inserting the Default Value under Certain Conditions - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

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