Templates and variables
Template variables allow you to create dynamic, reusable dashboards. Instead of hard-coding values like table names or filter criteria, you can use variables that users can change from a drop-down menu.
For more information about variables in Grafana, refer to Templates and variables.
Supported variable types
The SAP HANA plugin provides data source support for the following Grafana variable types:
Create a query variable
Query variables dynamically fetch values from your SAP HANA database using SQL queries.
To add a new SAP HANA query variable:
- From the Dashboard settings gear icon, click Variables.
- Click New variable.
- Select Query as the variable type.
- Select the SAP HANA data source.
- Enter your SQL query.
- Click Apply.
For general instructions, refer to Add a query variable.
Single column queries
The most common approach is to return a single column of distinct values.
Example:
The following query returns the distinct list of username from the users table:
SELECT DISTINCT("username") FROM "users"Key-value variable queries
You can create a variable with different display text and underlying values by returning two columns named __text and __value.
Example:
The following query uses host_name as the display text and host_id as the actual value:
SELECT host_name AS "__text", host_id AS "__value" FROM hosts_list_tableNote
The
__textcolumn value should be unique. If it’s not unique, the first value is used. Options in the drop-down have a friendly name as text and an ID as the value.
Query result behavior
The plugin handles query results as follows:
- 1 column: The column values become both the display text and the variable value.
- 2 columns: If columns are named
__textand__value, they’re used for display and value respectively. Otherwise, the first column is used for display and the second for value. - More than 2 columns: If columns named
__textand__valueexist, they’re used regardless of other columns. Otherwise, only the first column is used for both text and value.
Use variables in queries
You can use Grafana template variables anywhere in your SAP HANA queries. Variables are replaced with their current values when the query executes.
Single value variables
Use the standard variable syntax to insert a single value:
-- Query with variable
SELECT * FROM "users" WHERE "city" = ${city}
-- Expands to (when city = 'london')
SELECT * FROM "users" WHERE "city" = 'london'Numeric variables
Variables also work with numeric fields. In this example, ${age} is a text box variable that accepts numbers:
-- Query with variable
SELECT * FROM "users" WHERE "age" > ${age}
-- Expands to (when age = 36)
SELECT * FROM "users" WHERE "age" > '36'Multi-value variables
If your variable returns multiple values (multi-select enabled), use it with the IN clause. Note the parentheses around the variable:
-- Query with multi-value variable
SELECT * FROM "users" WHERE "city" IN (${cities})
-- Expands to (when cities = london, perth, delhi)
SELECT * FROM "users" WHERE "city" IN ('london','perth','delhi')You can also use the shorthand notation without curly braces:
SELECT * FROM "users" WHERE "city" IN ($cities)Variable syntax
The SAP HANA plugin supports multiple variable syntax formats:



