Altova DatabaseSpy 2024 Professional Edition

Running Multiple Named Queries

Home Prev Top Next

Whenever you run a query that returns some result from the database, the data is loaded in the Result window, for example:

dbs_zoo_named_queries_01

In the example above, the name of the Result window is Result1. This might not be informative enough when you work with multiple queries in the same project. To make the results more informative, it is possible to run multiple queries in the same script and display the results as separate named Result windows. For example, you may have one query that selects data from the tblAnimalCategories table and another one that selects data from tblAnimalTypes table. You can add both to the same SQL script and display their returned result sets separately. The name of each Result window is configurable.

To run multiple named queries:

1.Open the "ZooDB" project created previously and double-click the dbs_ic_connected ZooDBConnect data source to connect to it.

2.In the "SQL" folder, double-click the file animalType_queries.sql. The file opens in an SQL Editor window. As shown below, it contains two SELECT queries. Importantly, each query starts with a comment like --target: <tableName>. You can easily create such comments either by typing them manually, or by clicking the Define Target name ic_insert-target-single toolbar button.

dbs_zoo_named_queries_02

3.In the Properties window, make sure that either "Semicolons" or "SQL Grammar" is selected in the Group statements for execution with list.

dbs_zoo_named_queries_03

4.Click the Execute ic_execute-sql button or press F5.

 

The results of the two queries now appear in separate tabbed windows. As shown below, the name of each tab corresponds to the --target names that were set previously.

dbs_zoo_named_queries_04

You can also stack all the result windows, for example:

dbs_zoo_named_queries_05

To stack all windows, click the Show multiple results stacked ic_result-tabs option in the SQL Editor toolbar.

© 2017-2023 Altova GmbH