SET Statement
Assigns a value to a variable or procedure argument.
Syntax
SET varname = expression
Syntax Elements
varname
The name of the variable or procedure argument.
expression
An SQL expression. The value that results from evaluating the expression is
assigned to the specified variable or argument.
Comments
Local variables must be declared before they can be used.
Example
CREATE PROC EX7(@TYPE INTEGER IN) RETURNS DECIMAL(6,2) AS
BEGIN
DECLARE @V DECIMAL(6,2)
IF @TYPE=1
SET @V = (SELECT MIN(AMT) FROM TESTDATA)
ELSE IF @TYPE=2
SET @V = (SELECT MAX(AMT) FROM TESTDATA)
ELSE
SET @V = (SELECT AVG(AMT) FROM TESTDATA)
RETURN @V
END
Creates a procedure called EX7 that returns the minimum, maximum or average value from the AMT column of the TESTDATA table, depending on the value of the @TYPE parameter.
See Also
DECLARE statement, CREATE PROCEDURE statement.