<preamble>
When using <loop mode_="concat">
, the query code for each iteration
of the <inner>
clause is concatenated into a single query. The contents of a
<preamble>
clause are prepended to the concatenated code before the query
is executed.
Syntax
<loop with_="[ARBITRARY_VARIABLE_NAME]"> <outer> [1010data_QUERY] </outer> <preamble> [1010data_QUERY] </preamble> <inner> [1010data_QUERY] </inner> </loop>
Example
In the following example, the <preamble>
clause performs a tabulation
on the table pub.demo.retail.prod grouping on the sku
column. This query code is prepended to the two <link>
operations
resulting from the two iterations of the <inner>
corresponding to the
rows in the table from the <outer>
query. The resultant code is then
executed.
<loop with_="rpt" mode_="concat"> <outer> <table cols="start,end,period"> 20120515,20120602,1; 20120603,20120619,2; </table> </outer> <preamble> <base table="pub.demo.retail.prod"/> <tabu label="Sample Report" breaks="sku"/> </preamble> <inner> <link table2="pub.demo.retail.item" col="sku"> <sel value="between(date;{@rpt.start};{@rpt.end})"/> <tabu breaks="sku"> <tcol fun="sum" source="sales" name="sales_{@rpt.period}" label="Sales`[{format(@rpt.start;'type:date')} - {format(@rpt.end;'type:date')}]"/> </tabu> </link> </inner> </loop>
This results in the following code:
<base table="pub.demo.retail.prod"/> <tabu label="Sample Report" breaks="sku"/> <link table2="pub.demo.retail.item" col="sku"> <sel value="between(date;20120515;20120602)"/> <tabu breaks="sku"> <tcol fun="sum" source="sales" name="sales_1" label="Sales`[{format(20120515;'type:date')} - {format(20120602;'type:date')}]"/> </tabu> </link> <link table2="pub.demo.retail.item" col="sku"> <sel value="between(date;20120603;20120619)"/> <tabu breaks="sku"> <tcol fun="sum" source="sales" name="sales_2" label="Sales`[{format(20120603;'type:date')} - {format(20120619;'type:date')}]"/> </tabu> </link>
Note that the results would be different if the operations from the
<preamble>
were included in the <inner>
clause
instead.
<loop with_="rpt" mode_="concat"> <outer> <table cols="start,end,period"> 20120515,20120602,1; 20120603,20120619,2; </table> </outer> <inner> <base table="pub.demo.retail.prod"/> <tabu label="Sample Report" breaks="sku"/> <link table2="pub.demo.retail.item" col="sku"> <sel value="between(date;{@rpt.start};{@rpt.end})"/> <tabu breaks="sku"> <tcol fun="sum" source="sales" name="sales_{@rpt.period}" label="Sales`[{format(@rpt.start;'type:date')} - {format(@rpt.end;'type:date')}]"/> </tabu> </link> </inner> </loop>
Each iteration of the <inner>
clause would result in query code that
consisted of a <base>
, a <tabu>
, and a
<link>
operation. The concatenated code would result in the following
code:
<base table="pub.demo.retail.prod"/> <tabu label="Sample Report" breaks="sku"/> <link table2="pub.demo.retail.item" col="sku"> <sel value="between(date;20120515;20120602)"/> <tabu breaks="sku"> <tcol fun="sum" source="sales" name="sales_1" label="Sales`[{format(20120515;'type:date')} - {format(20120602;'type:date')}]"/> </tabu> </link> <base table="pub.demo.retail.prod"/> <tabu label="Sample Report" breaks="sku"/> <link table2="pub.demo.retail.item" col="sku"> <sel value="between(date;20120603;20120619)"/> <tabu breaks="sku"> <tcol fun="sum" source="sales" name="sales_2" label="Sales`[{format(20120603;'type:date')} - {format(20120619;'type:date')}]"/> </tabu> </link>
When this code is executed, the results would only include the operations after the second
base
tag, since any tags before a <base>
tag are
ignored. For more information, see <base>
.