> For the complete documentation index, see [llms.txt](https://v5docs.keyfax.biz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://v5docs.keyfax.biz/script-data/sql-query-databoxes.md).

# SQL query databoxes

Reads a value from a database, so a conversation can talk about a real tenancy, property or job rather than asking the caller for what you already know.

<figure><img src="/files/H5QQtTtQsRhofD9Z0qrH" alt="A SQL query databox open in the editor"><figcaption><p>A SQL query databox, with its database, its query, and the Test SQL button</p></figcaption></figure>

## The database

Which database to query. The box offers the names your SQL agent announced when it connected — they are suggestions rather than the only options, so a database added since can be typed in.

## The query

Written in the SQL query box. Two things make it a Keyfax query rather than a plain one:

* **Values from the conversation can be embedded.** Drag a databox read in from Insertable items, and it is substituted with its current value when the query runs. `{System.CallerNumber}` and `{System.DialledNumber}` are available the same way.
* **What comes back depends on Allow multiple records.** With it off you get the first row. With it on you get every row, which is what a [dynamic list](/scripts/questions/dynamic-list.md) needs.

## Test it before you rely on it

The **Test SQL** button runs the query then and there. Use it — a query that returns nothing, or returns something unexpected, is far cheaper to find here than in a conversation.

Two behaviours worth knowing:

* **An error message becomes the value.** A broken query does not stop the conversation; it quietly puts the error where the value should have been. If a script is showing something strange, this is the first thing to check.
* **Slow queries cost the caller.** A read has a time limit, and a query that regularly approaches it will occasionally exceed it. Keep queries narrow and indexed.
