Loops in Teradata

Teradata Loops

If<Condition>Then<Statement1>;

Else<Statment2>;

End If

 

Description

If the condition is successes if executes statement1, other wise executes statement2

 

While loop

While(<Condition>)Do

<SQL Statements>

End while;

 

Description

If repeats in till condition fails 

 

Looping[For Loop]

Loop Label: Label- Name

<Statements>

End loop Label- Name

 

Description

Till the condition False the loop will be Repeated

These core tutorials will help you to learn the Loops in Teradata. For an in-depth understanding and practical

experience, explore Teradata Training PDF.

 

Declaring variable

Syntax -  Declare<Variable name><Data type>;

Ex - Declare Dept name Varchar(30);

Assigning values to variables;

 

Syntax  - Set < Varchar >=<value>or<variable>or<columnname>

Ex

  1. Set Dept name=D Name1;
  2. Set Dept name= IT

 

Format command

9   2 Digit

Z   2 Zero Suppressed Digit

$2Under score etc

2  Formatting string

X 2 Single character

B 2 BLANK

Formatting Dates

DD 2 DAY

MMMM 2 Full month

YY 2 Year

YYYY 2 Full year

B 2 Blank etc…

85000 2 $9999 2 $85000

Learn more about Teradata Interview Questions in this blog post.

 

Screenshot_84

 

Note  Formatting command we can execute only in BTEQ

For Indepth knowledge on Teradata click on: