This article describes how to use queries to display SQL data in SquaredUp.
The SQL tile will only work if the SquaredUp server is domain joined. This is because the SquaredUp application pool account must be given permission to access the SQL database. We do not recommend including a username and password in the connection string, because this username and password will be visible to anyone with permission to view the page.
By default only SquaredUp administrators can create and edit SQL queries in SquaredUp. For more information see Signing and Security.
SQL tile types
The SQL tile enables you to pull data from external SQL data sources into your dashboards or perspectives.
SQL Scalar
The SQL Scalar tile should be used when the result of the query is a single number:
SQL Grid
The SQL Grid tile should be used for queries that return a table of results:
SQL Line Graph
A line graph can be displayed for any query that contains a DateTime field and a Numeric value field, as a minimum.
Prerequisites
Configure permissions in SQL Server Management Studio
See How to configure access to a database for use with the SQL tile
Connection String
Once the permissions are in place the connection string in the SQL tile is used to connect to the SQL server and database you want to query.
Connection String: Data Source=<SQLservername>;Initial Catalog=<DatabaseName>;Integrated Security=True;
For example:
Data Source=SQLServer1;Initial Catalog=CRMDB;Integrated Security=True;
We do not recommend including a username and password in the connection string, because this username and password will be visible to anyone with permission to view the page.
If the SquaredUp server and SQL server are in the same domain you can just use the SQL server name, if they are not in the same domain you should use the fully qualified domain name.
Specifying an instance
Connection String: Data Source=<SQLservername>\\<InstanceName>;Initial Catalog=<DatabaseName>;Integrated Security=True;
For example:
Data Source=SQLServer1\\Main;Initial Catalog=CRMDB;Integrated Security=True;
Specifying a port
Connection String: Data Source=<SQLservername>,<PortNumber>;Initial Catalog=<DatabaseName>;Integrated Security=True;
For example:
Data Source=SQLServer1,51433;Initial Catalog=CRMDB;Integrated Security=True;
Query String
First, run your query in SQL Server Management Studio, so you can see any errors and amend as necessary.
Check that your connection string corresponds with the server and database you were using in SQL Server Management Studio, and then paste your query into the query string box in the appropriate SQL Grid or Scalar tile.
Column Overrides
For the SQL Line Graph tiles there is a column overrides option following the query box. This important option allows you to choose how the data returned is grouped and displayed.
Timestamp
Use the timestamp dropdown to specify which data/column to use as the time series.
Value
Where there are multiple values it is possible to display these by expanding the column overrides section and then ticking the show all box next to value.
Grouping
If your results have more than one numeric column, SquaredUp will simply pick one to use as the line graph Y axis, or you can select the one you want.
Data Range
The Data Range option allows you to choose the range of the y-axis or bar chart area. The min and max will be set, depending on the option selected
percentage shows 0 to 100
fit to data shows the data minimum to data maximum
fit to data (from zero) shows from 0 to the data maximum
custom fit allows you to specify the min and max
Display
The height slider allows you stretch or shrink the graph height.
Label
show legend allows you to display a key to the coloured graph lines, which is particularly important for Open Access dashboards when users are not able to click on the lines to drilldown.
The custom label section allows you to change from the automatic label to specify your own label format. For more information see How to use custom labelling.
Walkthrough: Adding a SQL query to show a single figure
First, we will create a simple SQL Scalar tile:
- You can add the SQL tile to a new or existing dashboard or perspective. For this walkthrough we'll create a new dashboard. In SquaredUp navigate to where you'd like the dashboard to be created. Hover over the + button and click dashboard.
- Give the dashboard a title, by replacing the text that says New Dashboard.
- A new tile has already been added to the dashboard. Edit the title by overwriting the placeholder value New tile with your own title.
-
The tile selector will already be open. Click SQL.
-
Click on the SQL (Scalar) button to create a SQL Scalar tile.
- Type in the connection string for your database.
-
In the query string box paste in the SQL query you have tested in MS SQL Server Management Studio.
- Click next and the result of the query, as a single number will be shown.
- In the Scalar > unit box type the name of the units returned, for example it might be
disks
. - Click done.
Walkthrough: Adding a SQL query to show a table of results
- Under your SQL Scalar tile click the + to add another tile.
-
Click on the SQL (Grid) button to create a SQL Grid tile.
- Type in the connection string for your database.
- In the query string box paste in the SQL query you have tested in MS SQL Server Management Studio.
- Click next and you should see a table of results.
-
In the grid columns section we are now going to rename a column header and improve its formatting. To rename a column click on the column title and overwrite this with your new column name.
-
To format a column click on edit next to the column name. For example, for Unix timestamps you can paste in
{{timeago(value, true, true)}}
. For more information see How to use the Grid designer when configuring tiles. - Click done and then next.
- You can use the grid options row link option to add a hyperlink to each row.
- Click done.
- Test that the row linking works.
FAQs
Line Graph shows "A value column and a timestamp column are mandatory in the query results, please modify your query"
Both a DateTime field AND a Numeric value field are necessary for a line graph to be drawn. This message indicates that the query results are missing either a DateTime field, a Numeric value field or both.
Does the page timeframe affect the results?
No, the page timeframe has no effect on the query results. The timeframe should be configured in the SQL query.
How can I get dates and times to show correctly?
To to convert timestamps to show a readable date and time you can either edit the SQL query or customise the columns in the SquaredUp tile. See How to use the Grid designer when configuring tiles.
To show the date:
{{timeago(value, true, false)}}
To show the date and time:
{{timeago(value, true, true)}}
To return to showing how long ago it occurred:
{{timeago(value)}}
If you prefer to edit your SQL query to return your data in a date time format, you will need to insert the following into your SQL query string. The example below uses TimeRaised
, but you will need to edit this according to your query string:
CONVERT(varchar(64), TimeRaised, 21) as TimeRaised
You can configure the date format by editing 21
, replacing it with a chosen format which can be found in the following article:
Does the page timeframe affect the results?
No, the page timeframe has no effect on the query results. The timeframe should be configured in the SQL query.