Condividi tramite


Or Element (Query)

Applies to: SharePoint Foundation 2010

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

<Or>
</Or>

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

And, Or, Where

Occurrences

Minimum: 0

Maximum: Unbounded

Remarks

This element can be nested inside other Or and And elements. The server supports unlimited complicated queries. However, any given Or element can have only two disjuncts; that is, only two child elements. If you need to disjoin three or more conditions, you must nest the Or elements, as demonstrated by the second example in the following section.

Example

The following example performs a query for cases in which values of the Status field either do not equal Completed or are null. The results are sorted in descending order according to the Modified field.

<Query>
  <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
  </OrderBy>
  <Where>
    <Or>
      <Neq>
        <FieldRef Name="Status"></FieldRef>
        <Value Type="Text"></Value>
      </Neq>
      <IsNull>
        <FieldRef Name="Status"></FieldRef>
      </IsNull>
    </Or>
  </Where>
</Query>

The following example shows how to disjoin three conditions. Note that the first pair of conditions are within their own Or element, which is itself a condition of an outer Or element.

<Where>
  <Or>
    <Or>
      <Eq><FieldRef Name="LastName" />
        <Value Type="Text">Bagel</Value>
      </Eq>
      <Eq><FieldRef Name="LastName" />
        <Value Type="Text">Smith</Value>
      </Eq>
    </Or>
    <Includes>
      <FieldRef Name="Title" /><Value Type="Text">President</Value>
    </Includes>
  </Or>
</Where>