Using a SELECT Statement in a LET Statement
The examples in this section use a SELECT statement in a LET statement.
You can use a SELECT statement to assign values to one or more variables
on the left side of the equals ( = ) operator, as the following example
shows:
LET a,b = (SELECT c1,c2 FROM t WHERE id = 1); LET a,b,c = (SELECT c1,c2 FROM t WHERE id = 1), 15;
You cannot use a SELECT statement to make multiple values operate
on other values. The following example is invalid:
LET a,b = (SELECT c1,c2 FROM t) + (10,15); -- INVALID CODE
Because a LET statement is equivalent to a SELECT ... INTO statement,
the two statements in the following example have the same results:
a=c
and b=d
:
CREATE PROCEDURE proof() DEFINE a, b, c, d INT; LET a,b = (SELECT c1,c2 FROM t WHERE id = 1); SELECT c1, c2 INTO c, d FROM t WHERE id = 1 END PROCEDURE
If the SELECT statement returns more than one row, you must enclose the SELECT statement in a FOREACH loop.
For a description of SELECT syntax and usage, see SELECT statement.