Query Forms
Every dashboard can have parameters, these parameters are values that can be set from forms then used in the SQL queries to allow forming customized queries. For example if you had a query selecting employees from a table, you could create a form allowing an employer to be selected, then in the charts sql you can use that parameter to return only the employees from that employer. Let's look at an example.
To create and use a form we:
- Add a new Form
- Add an input Component to the Form
- Use the Parameter in an SQL query
Add a new Form
Add an input Component to the Form
Forms are used to group input components. Once you have added a form the form editor appears, we use the editor to add and configure components.
- First click on the Add ComboBox Component shown by the arrow.
- The key field is the name of our parameter, we will use this later our custom sql query.
- Options is a comma separated list of values that the user may choose from. (The list of options can also be created from an sql query, we'll cover this later)
- Label tells the end user what this input represents.
Here's an example input component that has been configured to give a list of countries as options
Use the Parameter in an SQL query
Finally we use the key field from our component within an SQL chart query, using a dollar symbol to mark it as a parameter, sqlDashboards then replaces that parameter with your selected value before sending the query to the SQL server. In this example we have selected Italy as the country and are displaying its GDP and population.
Dollar Symbols in SQL Queries
Note that $ symbol is special and must be escaped.. Since the $ symbol is used to represent a sqlDashboards form parameter, we must escape it to make it pass through to SQL raw. To do that we use double dollar symbols. e.g.
Select * from tradeTable where curreny='$$'would send only one dollar symbol to the SQL server.