Updated on 2024-07-19 GMT+08:00

Teradata Formats

Date in the YYYYMMDD Format

Input

Output

1
2
3
SELECT 1 FROM tb_dt_fmtyyyymmdd 
WHERE JobName ='${JOB_NAME}' 
AND TXDATE = ${TX_DATE} - 19000000;
SELECT 1 FROM tb_dt_fmtyyyymmdd 
WHERE JobName ='${JOB_NAME}' 
AND TXDATE = TO_DATE(${TX_DATE}, 'YYYYMMDD');

Date in the YYYYDDD Format

Input

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
REPLACE VIEW SC.VIEW_1 
 ( 
 col_1 
 ) 
 LOCKING TABLE sc.tab FOR ACCESS 
 AS 
 SEL 
 --tgt.col_1 is date type 
 CAST( CAST(TGT.col_1 AS DATE FORMAT 'YYYYDDD') AS CHAR(7) ) AS col_1 
 FROM 
 sc.tab TGT 
 ;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
CREATE 
      OR REPLACE VIEW SC.VIEW_1 (col_1)  
     /*LOCKING TABLE sc.tab FOR ACCESS */ 
      AS ( 
           SELECT 
                     /* tgt.col_1 is date type */ 
                     CAST( TO_DATE(TGT.col_1, 'YYYYDDD') AS CHAR( 7 ) ) AS col_1 
                FROM 
                     sc.tab TGT 
      ) ;

Column Names Starting with #

Input

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
REPLACE VIEW SC.VIEW_1 
 ( 
 ,col_1 
 ,#_col_2 
 ,#_col_3 
 ) 
 LOCKING TABLE sc.tab FOR ACCESS 
 AS 
 SEL 
 Tgt.col1 
 ,Tgt.#_col_2 
 ,Tgt.#_col_3 
 FROM 
 sc.tab TGT 
 ;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
CREATE 
      OR REPLACE VIEW SC.VIEW_1 ( 
           ,col_1 
           ,"#_COL_2" 
           ,"#_COL_3" 
      ) /*LOCKING TABLE sc.tab FOR ACCESS */ 
      AS ( 
           SELECT 
                     Tgt.col1 
                     ,Tgt."#_COL_2" 
                     ,Tgt."#_COL_3" 
                FROM 
                     sc.tab TGT 
      ) ;

Database Operations First During Type Casting

Input

Output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
REPLACE VIEW SC.VIEW_1 
 ( 
 col_1 
 ) 
 LOCKING TABLE sc.tab FOR ACCESS 
 AS 
 SEL 
 (COALESCE(TRIM(TGT.col_1),'')) || '_' || (COALESCE(TRIM(TGT.col_1),'')) (CHAR(22)) AS col_1 
 FROM 
 sc.tab TGT 
 ;
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
CREATE 
      OR REPLACE VIEW SC.VIEW_1 (col_1)  
     /*LOCKING TABLE sc.tab FOR ACCESS */ 
      AS ( 
           SELECT 
                    CAST(  
                     ( COALESCE( TRIM( TGT.col_1 ) ,'' ) ) || '_' || ( COALESCE( TRIM( TGT.col_1 ) ,'' ) ) 
                    AS CHAR( 22 ) ) AS col_1 
                FROM 
                     sc.tab TGT 
      ) ;