2021-09-10 22:04:40 +03:00
|
|
|
# Query in loop
|
2021-08-11 14:31:32 +03:00
|
|
|
|
2021-12-24 00:49:50 +03:00
|
|
|
It is recommended that you merge queries that address related data into a single query.
|
|
|
|
|
|
2021-08-11 14:31:32 +03:00
|
|
|
## Noncompliant Code Example
|
|
|
|
|
|
2021-12-24 00:49:50 +03:00
|
|
|
```bsl
|
|
|
|
|
// BanksToProcessing - contains an array of banks
|
|
|
|
|
|
|
|
|
|
InidividualQuery = New Query;
|
|
|
|
|
InidividualQuery.Text =
|
|
|
|
|
"SELECT
|
|
|
|
|
| BankAccounts.Ref AS Account
|
|
|
|
|
|FROM
|
|
|
|
|
| Catalog.BankAccounts AS BankAccounts
|
|
|
|
|
|WHERE
|
|
|
|
|
| BankAccounts.Bank = &Bank");
|
|
|
|
|
|
|
|
|
|
For Each Bank From BanksToProcess Do
|
|
|
|
|
InidividualQuery .SetParameter("Bank", Bank);
|
|
|
|
|
AccountsSelection = InidividualQuery .Execute().Select();
|
|
|
|
|
While AccountsSelection.Next() Do
|
|
|
|
|
ProcessBankAccounts(AccountsSelection.Account);
|
|
|
|
|
EndDo;
|
|
|
|
|
EndDo;
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-11 14:31:32 +03:00
|
|
|
## Compliant Solution
|
|
|
|
|
|
2021-12-24 00:49:50 +03:00
|
|
|
```bsl
|
|
|
|
|
// BanksToProcess - contains an array of banks
|
|
|
|
|
|
|
|
|
|
MergedQuery = New Query;
|
|
|
|
|
MergedQuery.Text =
|
|
|
|
|
"SELECT
|
|
|
|
|
| BankAccounts.Ref AS Account
|
|
|
|
|
|FROM
|
|
|
|
|
| Catalog.BankAccounts AS BankAccounts
|
|
|
|
|
|WHERE
|
|
|
|
|
| BankAccounts.Bank B(&BanksToProcess)";
|
|
|
|
|
|
|
|
|
|
MergedQuery.SetParameter("BanksToProcess", BanksToProcess);
|
|
|
|
|
|
|
|
|
|
AccountsSelection = MergedQuery.Execute().Select();
|
|
|
|
|
While AccountsSelection.Next() Do
|
|
|
|
|
ProcessBankAccounts(AccountsSelection.Account);
|
|
|
|
|
EndDo;
|
|
|
|
|
```
|
|
|
|
|
|
2021-08-11 14:31:32 +03:00
|
|
|
## See
|
|
|
|
|
|
2021-12-24 00:49:50 +03:00
|
|
|
https://support.1ci.com/hc/en-us/articles/360011001620-Multiple-execution-of-the-similar-queries
|
|
|
|
|
|
|
|
|
|
https://support.1ci.com/hc/en-us/articles/360011001540-Rounding-arithmetic-results-in-queries
|