How To Use The Retrieve Data Tag (FKA Query Tag)
Use the Retrieve Data Tag to retrieve a data set from your data source, then store that result in a newly created variable. The name of this variable can subsequently be used in other Tags using the "${VariableName}" syntax.
The Retrieve Data Tag holds a single row or node. If the result of the Retrieve Data Tag's select statement returns multiple rows or nodes, only the first one is accessible.
In this article we'll go through a step-by-step example of using a Retrieve Data Tag.
For more details about Retrieve Data Tags, see the Retrieve Data Tag Reference.
Open a new Word document, then connect to our public mssql.windward.net data source. If you're unfamiliar with connecting to a SQL Server data source, see How Do I Connect to Microsoft SQL Server?
Click on the Tags button in the Fluent ribbon, then select the Retrieve Data Tag:
Double-click on the Retrieve Data Tag to bring up the Tag Editor. Expand the Tables node in the Data Pane, then drag and drop the Employees table from the Data Pane onto the Retrieve Data Pane:
Then click on the Properties tab, give the Tag a nickname, and save the Tag:
To refine the Retrieve Data Tag select statement to return a single row, click on the Wizard button in the AutoTag ribbon:
For this example we'll narrow the select statement to return the employee with employee ID 5.
For more details about using the SQL Wizard, see the SQL Wizard Reference article.
Select the Retrieve Data Tag and click on the Preview button to see the row returned by the Retrieve Data Tag's new select statement:
Now we'll create some Out Tags to display the data held in the Retrieve Data Tag variable. Let's display the first name, last name and birth date of the employee with ID 5.
Enter some titles into your Word template like this:
Insert an Out Tag after each title like this:
We need to create a select statement for each Out Tag to return the data we wish to display.
- Select the first Out Tag
- Click on the
[Data Tree]
button in the AutoTag ribbon. At the top of the Data Tree window is a graphical view of the table columns returned by the Retrieve Data Tag (variable ${varName1}). - Select the FirstName column The Out Tag will now output the first name of the employee whose ID is 5.
Repeat this process for the other Tags. In addition, set the type of the [BirthDate] Out Tag to DATE by selecting that Tag and using the Type select list on the AutoTag ribbon:
Now save the template, generate output, and your output will look like: