Working with Batch Queries

The 1C:Enterprise 8. platform supports operations with query batches. In the batch query, the query texts are separated with semicolons (;). Queries will be executed sequentially; temporary tables that were created during any query execution will exist until the end of the entire query batch or until a query is executed in the batch destroying this temporary table. Example:

Query = New Query;
Query.Text =
"SELECT
| NomenclatureAccountingBalancesAndTurnovers.Nomenclature,
| NomenclatureAccountingBalancesAndTurnovers.QuantityReceipt,
| NomenclatureAccountingBalancesAndTurnovers.QuantityExpense,
| NomenclatureAccountingBalancesAndTurnovers.QuantityEndingBalance
|INTO NomenclatureAccounting
|FROM
| AccumulationRegister.NomenclatureAccounting.BalancesAndTurnovers(, , Auto, , ) AS NomenclatureAccountingBalancesAndTurnovers
    |;
    |
|SELECT
| NomenclatureAccounting.Nomenclature,
| NomenclatureAccounting.QuantityExpense,
| NomenclatureAccounting.QuantityEndingBalance
|FROM
| NomenclatureAccounting AS NomenclatureAccounting
    |"
;

Result=Query.Execute();

The first query creates a temporary table, the results of which are used in the second query.

If a temporary table manager is assigned to the Query object, temporary tables that were not terminated during the batch query will be saved in this manager. Within the text of a batch query, you may use and destroy temporary tables that existed in the assigned temporary table manager at the batch execution start point.

ExecuteBatch() Method

In addition to the Execute() method that executes all batch queries sequentially and returns the result of the last batch query, the 1C:Enterprise 8 platform provides another method, ExecuteBatch(). This method executes all queries sequentially and returns a result array for each query from the batch according to the succession of queries within the batch text. A query to terminate a temporary table results in the Undefined value, which will also be included in the result array.

1C:Enterprise Developer's Community