And 要素 (クエリ)

最終更新日: 2015年3月9日

適用対象: SharePoint Foundation 2010

この記事の内容
属性
子要素
親要素
出現回数

ビューのクエリにおいてフィルタをグループ化するために Where 要素内で使用します。

<And>
</And>

属性

属性

説明

なし

該当なし

子要素

AndBeginsWithContainsDateRangesOverlapEqGeqGtInIncludesIsNotNullIsNullLeqLtMembershipNeqNotIncludesOr

親要素

AndOrWhere

出現回数

最小: 0

最大: 制約なし

コメント

この要素は、他の And 要素および Or 要素内で入れ子にすることができます。サーバーは、無制限の複雑なクエリをサポートします。ただし、どのような And 要素も、持つことができるのは 2 つの合接詞のみ、つまり、2 つの子要素のみです。3 つ以上の条件を結合する必要がある場合、次のセクションの 3 番目の例で示されているように、And 要素を入れ子にする必要があります。

ProductID フィールドに対するクエリの条件を指定する例を次に示します。(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>

次の例では、Status フィールドの値が "Completed" と等しくなく、かつ Sent フィールドの値が null である場合にクエリを実行します。返されるレコードは、Modified フィールドの値に従って降順に並べ替えられます。

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

以下の例は、3 つの条件を結合する方法を示しています。最初の条件ペアは、独自の And 要素の内側にあり、これ自身が外側の And 要素の条件となっています。

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