SET | Teradata Vantage - SET - Teradata Vantage - Analytics Database

SQL Stored Procedures and Embedded SQL

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2023-10-30
dita:mapPath
frc1628111662093.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
rjx1472253414573
lifecycle
latest
Product Category
Teradata Vantage™

Assigns a value to a local variable or parameter in a stored procedure.

ANSI Compliance

SET is ANSI/ISO SQL:2011-compliant.

Required Privileges

None.

Invocation

Executable.

Stored procedures only.

Syntax

SET assignment_target = assignment_source ;

Syntax Elements

assignment_target
The name of the variable or parameter to be assigned a value.
assignment_source
The value to be assigned to assignment_source.

Usage Notes

  • All valid expressions except those containing subqueries are permitted in a SET statement assignment source.
  • Both assignment target and assignment source must be specified.
  • Assignment target is always on the left hand side (LHS) of the SET expression.
  • Assignment source is always on the right hand side (RHS) of the SET expression.
  • The data type of the assignment source must be compatible with the data type specified for the assignment target. Vantage performs implicit conversions for DateTime data types when the source data type differs from the target data type. For more information, see Teradata Vantage™ - Data Types and Literals, B035-1143.
FOR this component of a SET assignment … Valid Constructs Are... Invalid Constructs Are...
assignment target
  • Local variable name
  • OUT or INOUT parameter name
  • QUERY_BAND variable name
  • Status variable
  • FOR loop column and correlation name
  • IN parameter
assignment source a literal or an expression containing one of the following:
  • Local variable
  • IN or INOUT parameter
  • FOR loop column and correlation names when the SET statement is within the scope of the FOR statement
  • Constant expression
  • Status variable
  • An expression that evaluates to a UDT
  • OUT parameter
  • FOR loop column and correlation names when the SET statement is not within the scope of the FOR statement

Example: Using the SET Statement to Assign Values

The following example illustrates a valid use of the SET statement to assign values to variables and parameters.

SET hNoAccts = hNoAccts + 1;
SET hErrorText = 'SQLSTATE: '||sqlstate|| 
', SQLCODE: '||sqlcode||', ACTIVITY_COUNT: '
 ||activity_count;