DECLARE Statement

Declares one or more local variables for use in a procedure.

Syntax

DECLARE varname {AS} datatype {,varname {AS} datatype{...}}

Syntax Elements

variable
The name of the variable. This must obey the same rules as Table and Column names, except that it must start with an @ character.

datatype
Any supported SQL data type.

Comments

Local variables must be declared before they can be used.

Local variables are visible only within the procedure in which they are declared.

Examples

DECLARE @I AS INTEGER
DECLARE @V1 DECIMAL(6,2), @UKN VARCHAR(5)