Use wildcard characters in conditions for string values

You can use wildcard characters with the following operators when you build queries that include conditions on string values:

like
not-like
begins-with
not-begin-with
ends-with
not-end-with

More information: Query data using FetchXml

When you use these condition operators, you can use certain characters to represent wildcards in your search criteria. The following table describes the characters you can use.

Characters Description T-SQL Documentation and examples
% Matches any string of zero or more characters. This wildcard character can be used as either a prefix or a suffix. Percent character (Wildcard - Character(s) to Match) (Transact-SQL)
_ Matches any single character in a string comparison operation that involves pattern matching. _ (Wildcard - Match One Character) (Transact-SQL)
[] Matches any single character in the range or set that's specified between square brackets. [ ] (Wildcard - Character(s) to Match) (Transact-SQL)
[^] Matches any single character that isn't in the range or set that's specified between the square brackets. [^] (Wildcard - Character(s) Not to Match) (Transact-SQL)

Search for strings that contain wildcard characters

You can use the wildcard pattern matching characters as literal characters. To use a wildcard character as a literal character, enclose the wildcard character in brackets. More information: Using Wildcard Characters As Literals.

Don't use trailing wild cards

Using trailing wildcards isn't supported.

Don't use trailing wild cards in expressions using begins-with, not-begin-with, ends-with, or not-end-with. Here are some examples of trailing wildcards:

Bad Examples
<condition attribute='name' operator='begins-with' value='%value' />
<condition attribute='name' operator='not-begins-with' value='%value' />
<condition attribute='name' operator='ends-with' value='value%' />
<condition attribute='name' operator='not-ends-with' value='value%' />

Queries that use these anti-patterns introduce performance problems because the queries can't be optimized.

See also

Query data using FetchXml
Use the ConditionExpression class
Query data using the Web API