0 out of 1 rated this helpful - Rate this topic

Query Element (Query)

Windows SharePoint Services 3

Defines the query for a view.


<Query>
  <Where>
    ...
    </Where>
  <GroupBy>
    ...
    </GroupBy>
  <OrderBy>
    ...
    </OrderBy>
</Query>
Attribute Description

None

N/A

Minimum: 0

Maximum: 1

The following example queries the Status field for cases where the value does not equal Completed or is null, returning the results according to a descending sort on the Modified field. The Where element contains an Or element to group the filters.

<Query>
  <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
  </OrderBy>
  <Where>
    <Or>
      <Neq>
        <FieldRef Name="Status"></FieldRef>
        <Value Type="Text">Completed</Value>
      </Neq>
      <IsNull>
        <FieldRef Name="Status"></FieldRef>
      </IsNull>
    </Or>
  </Where>
</Query>
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Different notations

The where clause of the query is defined using prefix notation, meaning the operator comes in front of both operands.  i.e. operator operand1 operand2, so "and var1 = value1 var2 = value2"

Infix notation is what most English speakers are used to.  i.e. operand1 operator operand2, so "var1 = value1 and var2 = value2"

Finally postfix notation would be like the HP calculator.  i.e. operand1 operand2 operator, so "var1 = value1 var2 = value2 and"

Understanding CAML Query
Think of it as reverse polish logic, remember the HP calculators where you entered 4, 5, + and the answer was 9.

enter variable1, value1, eq, variable2, value2, eq, and, where, now reverse the order
to get
<where>
<and>
<eq> variable1, value1 </eq>
<eq> variable2, value2 </eq>
</and>
</where>

which is equal to

select * from list
where variable1 = value1 and variable2 = value2