2009-02-27 91 views
2

任何人都可以帮助我使用此CAML查询吗?当我将Ascending属性从TRUE翻转到FALSE(也尝试过TrueFalse)时,它不会重新排序结果集。CAML查询没有正确订购

其余的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> 

回答

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

+0

doh!我盯着查询这么久,我没有看到明显的答案。是的,我建立了生成查询的工具。对于IncludeTimeValue,为 – Jason 2009-02-27 12:15:58

4

我上面的答案达成一致,该<查询>必须<凡>之外。 另请注意,使用日期时间字段比较时,它通常是一个好主意,包括IncludeTimeValue属性:

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

并将其设置为或真或假,这取决于你是否要包含的值,或者不是在你的查询。

+0

+1 – Jason 2009-02-27 12:16:36

0

我花了差不多整整一个星期的时间尝试使用Client OM CamlQuery对象获取日期订单。最后,我意识到,我必须设置

camlQuery.DatesInUtc = true; 

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