In SQLMessenger, you can configure a recipient list within a task. SQLMessenger runs the SQL query individually for each recipient in the list and sends the resulting dataset to that recipient. This type of task is known as a Report Distribution Task.
When the system runs a Report Distribution Task, it first creates a task instance for the task (this instance is referred to as the "parent task instance"). The parent task instance reads the "Recipient List (Loop Data)" from the specified data source and generates sub-task instances for each record in the list. It also passes the corresponding record data from the list as parameters to the sub-task instances. The sub-task instances process the email body template and attachment templates, then generate the outbound emails. Within sub-task instances, you can use `@@LoopData(Column Name)` to retrieve data for the matching record in the "Recipient List (Loop Data)". The parent task instance completes and exits only after all sub-task instances have finished executing.
The following is a typical execution flow of a Report Distribution Task:

The execution flow of the parent task instance

The execution flow of a sub-task instance
To create a Report Distribution task, you first need to enable the Generate unique reports for each recipient in the list option on the Report Distribution page of the task editor.

Enable the Generate unique reports for each recipient in the list option for the task
The Recipient List holds information for the recipients you want to send reports to. SQLMessenger generates a sub-task for each record in the list and passes that record’s data as parameters to the sub-task.
You can save the recipient list in a spreadsheet or CSV file and import this file when configuring the task. Alternatively, you can save the recipient list in a table in a database, and the system will read the list from this table during task execution.

Click the Recipient List button to open the Recipient List(Loop Data) Config dialog box

The Recipient List(Loop Data) Config dialog box
If the Recipient List is saved in a file, you can select Excel or CSV file as the data source and then choose the Excel or CSV file. The system will import the content of the file into the task configuration.

Select Excel or CSV file as the data source
If the Recipient List is saved in an Excel file, the list data should be saved in the first sheet of the file.
The first row of the table is the header row, and the data rows start from the second row. Column headers must not be empty, and column names must not be duplicated.

Recipient List in an Excel file
Note: If the Recipient List is stored in a file, after you modify the data in the file, you need to re-import the updated file in the task configuration.
If the Recipient List is stored in a database table, you need to select the data source where this table is located and enter the SQL query used to retrieve the Recipient List. After entering the SQL query, click the "Test SQL" button. The system will execute the SQL query and retrieve the field information returned by the query.

Configure the task to read the Recipient List from the database during runtime
After setting up the Recipient List, you need to modify the query statements to query data individually for each recipient. For example, consider the following SQL statement:
SELECT *
FROM sales_stat
WHERE city = 'Birmingham' --Query sales reports for a specified region
ORDER BY stat_month;
In a Report Distribution Task, you need to replace the query conditions in the statement with the variable @@LoopData(Column Name), which uses the field data from the corresponding record in the Recipient List as the query condition. The modified statement is as follows:
SELECT *
FROM sales_stat
WHERE city = #[@@LoopData(City)]# --Query sales reports for a specified region,use the column "City" from the Recipient List as query criteria.
ORDER BY stat_month;
In the modified statement, use @@LoopData(City) to get the data from the City column of the corresponding record in the Recipient List as the query parameter in the SQL statement, thus querying data only for a specific recipient.
Using Variables in Tasks, Using Variables in SQL Statements, Using JDBC Variables
If SQL commands need to run within sub-task instances, you must change the Execute command in option for the SQL command to either the sub-tasks generated by the task or the task itself and its generated sub-tasks. This ensures the SQL commands run inside the sub-task instances.
For example, if we need to verify in a sub-task instance whether there are sales report data available for a specific region, and if not, abort the current sub-task instance without affecting the execution of other region's sub-task instances, we can use the following SQL command:

Execute an SQL Command in sub-task instance
To send separate emails to each recipient, you must use @@LoopData for the task recipient. For example, if the Manager Email column in the Recipient List holds the recipient’s email address, set the task recipient to @@LoopData(Manager Email), as shown below:

Set "@@LoopData(Manager Email)" as the recipients for the task
Set Recipients for Report Distribution Tasks
(1) After a sub-task instance completes its execution, the email it generates will be sent immediately by the system, without waiting for all sub-task instances to finish.
(2) You can enable the option Send task-generated emails and messages only after my review, so that the emails generated will need your review before being sent.
(3) If the Recipient List's data source is Excel or CSV file, and you imported an empty spreadsheet or CSV file (containing only header rows without any data rows) when configuring the task, you will need to manually start this task. During task startup, you must import a file containing the Recipient List data. The format of the imported file should match the template file of the Recipient List used during task configuration. Start Tasks Manually