【问题标题】:CAML Query not ordering properlyCAML 查询未正确排序
【发布时间】:2009-02-27 07:37:49
【问题描述】:

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

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>

【问题讨论】:

    标签: sharepoint caml


    【解决方案1】:

    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

    【讨论】:

    • 哇!我盯着问题看了这么久,我没有看到明显的答案。是的,我构建了生成查询的工具。
    【解决方案2】:

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

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

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

    【讨论】:

      【解决方案3】:

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

      camlQuery.DatesInUtc = true;
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多