Contains Text

Learn how to compare and evaluate text stored within a Keyfax databox.

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.

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.

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.

You can see this example below...

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...

SQL databox

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 );

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.

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.

Message with Bookmarks / Databoxes

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...

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...

Should you have any further quesitons please don't hesitate to Contact Us

Last updated