views:

1014

answers:

2

Can anyone help me with this CAML query? When I flip the Ascending attribute from TRUE to FALSE (have also tried True and False), it doesn't re-order the result set.

The rest of the CAML is correct, it is being generated by a tool and the appropriate results are being returned.

<Where>
  <And>
    <And>
      <Eq>
        <FieldRef Name="Branch"/>
        <Value Type="Text">Camp 1</Value>
      </Eq>      
      <Eq>
        <FieldRef Name="Type"/>
        <Value Type="Choice">Day</Value>
      </Eq>
    </And>
    <Geq>
      <FieldRef Name="StartDateTime"/>
      <Value Type="DateTime">2009-01-05T00:00:00Z</Value>
    </Geq>
  </And>
  <OrderBy>
    <FieldRef Ascending="TRUE" Name="Title" />
  </OrderBy>
</Where>
+2  A: 

Doesn't the OrderBy have to be outside the Where clause?

    <Where>
  <And>
    <And>
      <Eq>
        <FieldRef Name="Branch"/>
        <Value Type="Text">Camp 1</Value>
      </Eq>      
      <Eq>
        <FieldRef Name="Type"/>
        <Value Type="Choice">Day</Value>
      </Eq>
    </And>
    <Geq>
      <FieldRef Name="StartDateTime"/>
      <Value Type="DateTime">2009-01-05T00:00:00Z</Value>
    </Geq>
  </And>
  </Where>
<OrderBy>
    <FieldRef Ascending="TRUE" Name="Title" />
  </OrderBy>

See http://msdn.microsoft.com/en-us/library/ms442728.aspx

Jamie McAllister
doh! i was staring at the query so long, i didn't see the obvious answer. yes, i built the tool generating the query.
Jason
+1  A: 

I agree with the answer above, the must be outside the . Please also note that when comparing with DateTime fields, it's generally a good idea to include the IncludeTimeValue attribute:

<Geq>
      <FieldRef Name="StartDateTime"/>
      <Value Type="DateTime" IncludeTimeValue="FALSE">2009-01-05T00:00:00Z</Value>
</Geq>

... and set it to false or true, depending on whether you want to include time values or not in your query.
Tudor Olariu
+1 for IncludeTimeValue
Jason