PreviousSQL Engine Reference (v9 SP2 (9.5) revision 1) Next

DECLARE

Chapter contents

Remarks

Use the DECLARE statement to define an SQL variable.

This statement is allowed only inside of a stored procedure, a user-defined function, or a trigger.

The name of a variable must begin with a colon (:), both in the definition and use of the variable or parameter. A variable must be declared before it can be set to a value with SET.

Use a separate DECLARE statement for each variable (you cannot declare multiple variables with a single statement). Specify a value or values for data types that require a size, precision, or scale, such as CHAR, DECIMAL, NUMERIC, and VARCHAR.

Examples

The following examples show how to declare variables, including ones that require a value for size, precision, or scale.

DECLARE :SaleItem CHAR(15); 
DECLARE :CruiseLine CHAR(25) DEFAULT 'Open Seas Tours' 
DECLARE :UnitWeight DECIMAL(10,3); 
DECLARE :Titration NUMERIC(12,3); 
DECLARE :ReasonForReturn VARCHAR(200); 
DECLARE :Counter INTEGER = 0; 
DECLARE :CurrentCapacity INTEGER = 9; 
DECLARE :Cust_ID UNIQUEIDENTIFIER = NEWID() 
DECLARE :ISO_ID UNIQUEIDENTIFIER = '1129619D-772C-AAAB-
B221-00FF00FF0099' 

See Also

CREATE FUNCTION

CREATE PROCEDURE

CREATE TRIGGER

SET


Chapter contents
Book contents

Prev topic: CREATE VIEW
Next topic: DECLARE CURSOR