2

谁能帮我解决这个 CAML 查询?当我将Ascending属性从TRUEto翻转FALSE(也尝试过Trueand False)时,它不会重新排序结果集。

CAML 的其余部分是正确的,它是由工具生成的,并且正在返回适当的结果。

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

3 回答 3

9

OrderBy 不是必须在 Where 子句之外吗?

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

请参阅http://msdn.microsoft.com/en-us/library/ms442728.aspx

于 2009-02-27T10:33:47.993 回答
4

我同意上面的答案,<Query> 必须在 <Where> 之外。另请注意,在与 DateTime 字段进行比较时,通常最好包含 IncludeTimeValue 属性:

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

并将其设置为 false 或 true,具体取决于您是否要在查询中包含时间值。

于 2009-02-27T11:29:26.987 回答
0

我花了将近一整周的时间尝试使用 Client OM CamlQuery 对象让日期订单正常工作。最后我意识到我必须设置

camlQuery.DatesInUtc = true;

在我看来,如果您使用本机对象模型和 SPQuery 对象,那么当您使用 ClientOM 移动到 CamlQuery 对象时,SharePoint 默认将该日期解释为 UTC(在我们的环境中),您需要设置此参数。

于 2015-06-22T09:01:28.407 回答