<letseq>
<letseq>
is used within a <block>
, or
independently in place of a <block>
, and can be used to assign new values to
variables defined within the block or to define new variables. In addition, variables may be
defined in terms of earlier variables in the same <letseq>
.
Description
The form <letseq [VAR_1]="A"
[VAR_2]="B"> [CONTENTS] </letseq>
expands [CONTENTS] with [VAR_1] and
[VAR_2] defined. The values of these variables may be referenced (along
with other block variables) with the {@[VAR]}
syntax
within expressions in [CONTENTS].
In addition, unlike <let>
, variables may
be defined in terms of earlier variables in the same <letseq>
by
referencing them using the {@[VAR]}
syntax.
Variables defined within a <letseq>
only have scope within the
<letseq></letseq>
itself.
<letseq>
element can be used in the same way a
<block>
is used, only without the
name="[BLOCK_NAME]"
portion of the opening
tag.Syntax
<letseq [USER_DEFINED_VAR_1]="[VALUE_1]" ...
[USER_DEFINED_VAR_N]="[VALUE_N]">
[CONTENTS]
</letseq>
Attributes
[USER_DEFINED_VAR_x]
- Accepts a string that will act as a user-defined variable. The variable name must
begin with a lowercase alphabetic character and consist only of lowercase alphanumeric
characters, digits, and/or underscores.
The block element may include any number of additional attributes, which may be used as parameters in the Macro Language code contained within the element. The value of a user-defined variable (e.g.,
my_var
) is substituted wherever a scalar expression containing a reference to it (e.g.,{@my_var}
) appears within the block element.
Example
In this example, the base table is pub.demo.retail.item
, and the objective
is to select rows between a minimum and maximum cost. And let's say that the maximum cost
depends on the value of the minimum cost.
We can use <letseq>
to define the minimum and maximum cost as
variables. Since <letseq>
allows us to reference variables defined
earlier in the same operation, we can define the maximum cost in terms of the minimum cost.
Then, we can use these variables in a <sel>
operation to select the rows that we're interested
in.
In the following <letseq>
statement, we define
minimum_cost
to be 1.50 and maximum_cost
as 5.00 more
than minimum_cost
. We'll also use the between
function
in the value expression used by the <sel>
operator.
So, our query looks like:
<base table="pub.demo.retail.item"/> <letseq minimum_cost="1.50" maximum_cost="{@minimum_cost}+5.00"> <sel value="between(cost;{@minimum_cost};{@maximum_cost})"/> </letseq>
This query expands to:
<sel value="between(cost;1.50;1.50+5.00)"/>