Editar

Partilhar via


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 leading wild cards

Queries which use condition operators with implicit leading wild cards (like ends-with) or explicit leading wild cards will be less performant and can lead to poor performance across the organization in certain scenarios. More information:

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

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

Bad Examples
<condition attribute='name' operator='like' value='%value' />
<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' />

See also

Filter rows using FetchXml
Filter rows using QueryExpression
Query data using the Web API