Skip to content

Latest commit

 

History

History
123 lines (89 loc) · 5.52 KB

wildcard-characters.md

File metadata and controls

123 lines (89 loc) · 5.52 KB
title description ms.date ms.reviewer ms.topic author ms.author ms.subservice search.audienceType contributors ms.custom
Use wildcard characters in conditions for string values
Learn how to use wildcard characters in query conditions that use string values.
06/04/2024
jdaly
conceptual
mayadumesh
mayadu
dataverse-developer
developer
JimDaly
bap-template

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

xref:Microsoft.Xrm.Sdk.Query.ConditionOperator.Like
xref:Microsoft.Xrm.Sdk.Query.ConditionOperator.NotLike
xref:Microsoft.Xrm.Sdk.Query.ConditionOperator.BeginsWith
xref:Microsoft.Xrm.Sdk.Query.ConditionOperator.DoesNotBeginWith
xref:Microsoft.Xrm.Sdk.Query.ConditionOperator.EndsWith
xref:Microsoft.Xrm.Sdk.Query.ConditionOperator.DoesNotEndWith

More information: Filter rows using QueryExpression

contains
not contains
startswith
not startswith
endswith
not endswith

More information: Use OData query functions


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' />

Don't use leading wild cards in expressions using Like, BeginsWith, DoesNotBeginWith, EndsWith, or DoesNotEndWith. Here are some examples of excess wildcards:

Bad Examples
query.Criteria.AddCondition("name", ConditionOperator.Like, "%value");
query.Criteria.AddCondition("name", ConditionOperator.BeginsWith, "%value");
query.Criteria.AddCondition("name", ConditionOperator.DoesNotBeginWith, "%value");
query.Criteria.AddCondition("name", ConditionOperator.EndsWith, "value");
query.Criteria.AddCondition("name", ConditionOperator.DoesNotEndWith, "value");

Don't use leading wild cards in expressions using like, startswith, not startswith, endswith, or not endswith. Here are some examples of excess wildcards:

Bad Examples
like(name,'%value')
startswith(name,'%value')
not startswith(name,'%value')
endswith(name,'value%')
not endswith(name,'value%')

See also

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

[!INCLUDEfooter-include]