SQL Query

Using SQL Query Databoxes in your scripts

Introduction

SQL Query Databoxes are powerful and can return a variety of information from a host system's database(s) which could prove useful in the course of a diagnostics script either by controlling the flow, minimising the number of questions asked or for displaying relevant information that assist the call handler or end user alike. For example, they are often used:

  • in Startup scripts to decide which set of scripts to use, e.g. General, Leasehold, Communal

  • to provide additional tenant/caller profile data, e.g. date of birth, vulnerability indicators, warnings. no. of bedrooms

  • to provide additional asset related information, e.g. heating type, in defects, void property, repair responsibilities

  • historical information e.g. previous repairs or enquiries

  • present rent account information in Messages

SQL Queries can be issued against any configured/compliant database in order to return a single row of data which internally is held as an XML packet and can be referenced by Expressions, e.g. 'Item' (see example below).

Select an existing SQL Databox or click Add to create afresh.

An SQL Query Databox

Properties

Group - when displayed in the Selection List, Databoxes are arranged into groups. Select a group from the drop down list to add the Databox to an existing group or type in a new group name to create a new group.

Database - the database drop-down list specifies which database connection the SQL Query Databox will access. By default the Keyfax Database is available. If you are wishing to query other SQL databases these will need to be added by Support, to do this read-only login credentials will be needed, along with database name and location. The necessary permissions will also need to be established.

Name – a descriptive name for the Databox. If you can, make this a meaningful description to enable easy identification in your scripts..

Empty bookmarks allowed – check this box if the Databox can be used in a Task or Message without being required to hold a value.

Description - a short description of the Databox. This is displayed in the Databox Selection list in and is searchable using the filter.

SQL Query – This is where the SQL query is added. The Query normally includes a reference to another Databox, for example, a Databox obtaining the AssetID of a property. The maximum length of the query is around 1900 characters; this varies depending on the selected database name and the possible references to other Databoxes. Longer SQL queries should be set up as Stored Procedures in the database with EXECUTE permissions granted to the role: OMFAXROLE. The Databox SQL can then simply execute the stored procedure with the appropriate parameters.

Note that there is no need to specify a database name as part of your SQL query. For example, in the statement:

SELECT PropertyType FROM PropertyDb.dbo.Assets

mention of 'PropertyDb' should be omitted. By selecting the correct Database (from the dropdown list) when editing the SQL Databox, the Query will be executed against the chosen database.

Test – test the SQL and Expressions setup against the databox.

Expressions – these are covered in-depth in the Databox Expressions section. Typically, the Expression Item will be used to access individual columns returned by the query. In the example above you'll see four Item Expressions which point at Name, Email, Telephone and TelephoneExt which match up exactly with the column names returned.

In the above example...

The example retrieves four items, e.g. the user's Name, Email, Telephone and Extension No. The key piece of data (used in the WHERE clause) is '{Import.UserCode}' that has been supplied by the host system.

As you can see in the Expression list, each element of data can be referenced separately.

To ensure the SQL query and its Expressions are working, click Test.

If an SQL query returns just a single column, this will not result in an XML packet and the value of the Databox will be the value returned and no Expression is required.

Handling multiple rows of data

Last updated