And Element (Query)
Applies to: SharePoint Foundation 2010
Used within the Where element to group filters in a query for a view.
<And>
</And>
Attributes
Attribute |
Description |
---|---|
None |
N/A |
Child Elements
And, BeginsWith, Contains, DateRangesOverlap, Eq, Geq, Gt, In, Includes, IsNotNull, IsNull, Leq, Lt, Membership, Neq, NotIncludes, Or |
Parent Elements
Occurrences
Minimum: 0 Maximum: Unbounded |
Remarks
This element can be nested inside other And and Or elements. The server supports unlimited complicated queries. However, any given And element can have only two conjuncts; that is, only two child elements. If you need to conjoin three or more conditions, you must nest the And elements, as demonstrated by the third example in the following section.
Example
The following example conveys criteria for a query on the ProductID field: (ProductID = J1539 AND ProductID = J9862) AND (ProductID = J0394 OR ProductID = J4589).
<And>
<And>
<Eq>
<FieldRef Name="ProductID"/>
<Value Type="Text">J1539</Value>
</Eq>
<Eq>
<FieldRef Name="ProductID"/>
<Value Type="Text">J9862</Value>
</Eq>
</And>
<Or>
<Eq>
<FieldRef Name="ProductID"/>
<Value Type="Text">J0394</Value>
</Eq>
<Eq>
<FieldRef Name="ProductID"/>
<Value Type="Text">J4589</Value>
</Eq>
</Or>
</And>
The following example performs a query for cases in which values of the Status field do not equal Completed and values of the Sent field are null. The records returned are sorted in descending order according to values of the Modified field.
<Query>
<OrderBy>
<FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
</OrderBy>
<Where>
<And>
<Neq>
<FieldRef Name="Status"></FieldRef>
<Value Type="Text">Completed</Value>
</Neq>
<IsNull>
<FieldRef Name="Sent"></FieldRef>
</IsNull>
</And>
</Where>
</Query>
The following example shows how to conjoin three conditions. Note that the first pair of conditions are within their own And element, which is itself a condition of an outer And element.
<Where>
<And>
<And>
<Eq><FieldRef Name="LastName" />
<Value Type="Text">Bagel</Value>
</Eq>
<Eq><FieldRef Name="FirstName" />
<Value Type="Text">Jean</Value>
</Eq>
</And>
<Includes>
<FieldRef Name="Title" /><Value Type="Text">President</Value>
</Includes>
</And>
</Where>