PROBLEM

A wildcard query cannot be performed in an attribute table

Last Published: April 25, 2020

Description

In ArcMap, an SQL query performed on an attribute table to select a particular set of digits from a field is not possible.

A wildcard query is used to substitute any other character in a string. When a wildcard query is carried out using an attribute query, the following error is returned:

Error:
An invalid SQL statement was used.

The error is returned during the verification of the expression.

Cause

This issue occurs when a wildcard query is carried out on a numerical field using an expression such as the one displayed below.

FIELD LIKE '42041%'

Wildcard symbols such as the percent sign and the asterisk can only be used in a string field.

Solution or Workaround

There are two options to perform a wildcard query on an attribute table.

  • Using the CAST function
  • Creating a new string field

If the first option cannot be carried out, apply the second.

Use the CAST function in the attribute table

In this example, the CAST() function converts the field to a string of characters to allow the wildcard query on the number field.

  1. Right-click the selected layer in the Table Of Contents and select Open Attribute Table.
Open Attribute Table
  1. Click the Select By Attributes tool Select by Attributes tool in the attribute table to open the tool's dialog box.
Tool dialog box
  1. Type the script as highlighted below to select a particular set of field cells containing the digits 128.
CAST(Field_Name AS VARCHAR(12)) LIKE '323%' 
Note:
VARCHAR denotes the character length and must be specified when using the CAST function.
  1. Click the Verify button to verify the expression.
  2. Click the Apply button, and the particular set of digits is selected.
Digits selected

Create a new string field, and compute the old field to the new field

  1. Right-click the selected layer in the Table Of Contents and select Open Attribute Table.
  2. Click the Table Options drop-down arrow and select Add Field.

Add Field

  1. In the Add Field dialog box, set the field name and select Text as the data type.

Select Text as data type

  1. Click OK.
  2. Right-click the newly created field and select Field Calculator.

Select Field Calculator

  1. If a warning on calculating outside of an edit session is displayed, click Yes.
  2. Double-click the numeric field from the Fields list to populate the new field with values from the selected field.
Populate the new field
  1. Click the Select By Attribute tool in the attribute table to open the tool's dialog box.
  2. Type the following expression to return field cells with digits of 127.
New_Text_field LIKE '324%' 
  1. Click the Verify button to verify the expression.
  2. Click the Apply button, and a particular set of digits in a field is selected.
Set of digits is selected

Article ID: 000012434

Software:
  • ArcMap

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options