Export (0) Print
Expand All

And Element (Query)

Last modified: February 03, 2012

Applies to: SharePoint Foundation 2013 | SharePoint Server 2013

In this article
Attributes
Child Elements
Parent Elements
Occurrences

Used within the Where element to group filters in a query for a view.


<And>
</And>

Attribute

Description

None

N/A

Minimum: 0

Maximum: Unbounded

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.

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>

Show:
© 2014 Microsoft