# Contains Text

To check for the presence of a specific string within a databox the following approaches can be used. Which approach you use may depend upon your specific requirements.&#x20;

{% hint style="danger" %}
**DANGER** It's important when using the CHARINDEX function and / or LIKE operator below that you don't allow user supplied input within your SQL databoxes. Only fixed text databoxes or hardcoded values should be allowed within Keyfax SQL databoxes.
{% endhint %}

### CHARINDEX Function

In the example below we've created 2 text questions asking the user for text to search and the string to find. This supplied input is captured within two Script databoxes.&#x20;

The "Text is present" SQL databox below is then used to check if the "Text to search" Script databox value contains the string captured within the "Text to find" Script databox value.&#x20;

You can see this example below\...

<figure><img src="/files/1eoHR2IR6A8VoZooZs5y" alt=""><figcaption></figcaption></figure>

The "Text is present" SQL databox above performs the logic to determine if the string was found anywhere within the source string as shown below\...

<figure><img src="/files/OSEKmePpuDlA279GJ92a" alt=""><figcaption><p>SQL databox</p></figcaption></figure>

The SQL code for the above SQL databox is enclosed below\...

```
DECLARE @find NVARCHAR(MAX) = '{Script.Text to find}';
DECLARE @source NVARCHAR(MAX) = '{Script.Text to search}';
SELECT CHARINDEX(@find , @source );
```

{% hint style="info" %}
**NOTE** The `{Script.Text to find}`and `{Script.Text to search}`Script databoxes used in the example above are only provided for example purposes and these will likely need to change within your real implementation.
{% endhint %}

To verify this is working as expected during development the following message could be displayed if a match is found (i.e. the SQL databox returned 1 or above). 0 will be returned if no match is found.&#x20;

<figure><img src="/files/FRhRMt7HOycNKzjJ12vm" alt=""><figcaption><p>Message with Bookmarks / Databoxes</p></figcaption></figure>

You can use the "Test" button to test your SQL databox via Keyfax Administrator Tools. Within Keyfax you would then see the test message from above like so to verify the string is being found...

<figure><img src="/files/iei9vhOD7uBxqGVLYU0P" alt=""><figcaption></figcaption></figure>

### LIKE Operator

The LIKE operator is used in a WHERE clause to search for a specified pattern in a string.

There are two wildcards often used in conjunction with the LIKE operator:

* The percent sign `%` represents zero, one, or multiple characters
* The underscore sign `_` represents one, single character

For example the following SQL databox will return 1 if the databox value contains AST and zero or more characters after...

<figure><img src="/files/rU9qFFDTiFj5z6vBQRAq" alt=""><figcaption></figcaption></figure>

Should you have any further quesitons please don't hesitate to [Contact Us](/links/support.md)

{% hint style="info" %}
An alternative means to find text within a comma separated list of items is the use of [IndexOf](/readme.md).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keyfax.biz/product-suite/admin/databox-examples/contains-text.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
