问题描述
我有一个像这样工作的 Caml 查询:
I have a working Caml Query like so:
<View><Query><Where><Eq><FieldRef Name=\'ptli_TravelersEmail\' /><Value Type=\'Text\'>' + payeename + '</Value></Eq></Where></Query></View>
...从 Sharepoint 列表中检索记录",其中ptli_TravelersEmail"字段中的值等于传入参数payeename"的值.
...that retrieves "records" from a Sharepoint list where the value in the 'ptli_TravelersEmail' field equates to the value of the passed-in arg "payeename".
要在查询中添加另一个子句,检索记录",其中前者成立,而且ptli_preparer"字段中的值等于传入参数用户名"的值,我是否需要重复整个Where.Eq.FieldRef Name.Value..Value.Eq.Where"部分,如下所示:
To add another clause to the query, to retrieve "records" where the former holds true but also where the value in the 'ptli_preparer' field equates to the value of the passed-in arg "username," do I need to repeat an entire "Where.Eq.FieldRef Name.Value..Value.Eq.Where" section, like this:
<View><Query><Where><Eq><FieldRef Name=\'ptli_TravelersEmail\' /><Value Type=\'Text\'>' + payeename + '</Value></Eq></Where><Where><Eq><FieldRef Name=\'ptli_preparer\' /><Value Type=\'Text\'>' + username + '</Value></Eq></Where></Query></View>
...还是我的语法不对?
...or is my syntax off?
我可以尝试并找出答案,我知道,但是 Sharepoint 中的构建/运行/测试过程需要很长时间,我希望一些 Caml 专家立即知道.
I could just try it and find out, I know, but the build/run/test process in Sharepoint takes quite awhile, and I'm hoping some Caml expert knows right off the bat.
推荐答案
以下是 CAML 查询:
<View>
<Query>
<Where>
<Eq>
<FieldRef Name="Internal_Name_of_field" />
<Value Type="Text">The value to filter against</Value>
</Eq>
</Where>
</Query>
</View>
表示等于".您还可以使用诸如
(不等于)、
(小于)、
(小于或等于)、
(大于)、
(大于或等于)、
、
和
.
<Eq>
means "Equals." You can also use comparisons like <Neq>
(Not Equals), <Lt>
(Less than), <Leq>
(Less than or equal to), <Gt>
(Greater than), <Geq>
(Greater than or equal to), <Contains>
, <IsNull>
, and <IsNotNull>
.
当您希望 CAML 查询具有多个条件时,您可以在一组 <And>
标记 (此处记录.
When you want your CAML query to have multiple conditions, you can combine two of them inside a set of <And>
tags (documented here).
<Where>
<And>
<Eq>
<FieldRef Name="Internal_Name_of_field1" />
<Value Type="Text">The value to filter against</Value>
</Eq>
<Eq>
<FieldRef Name="Internal_Name_of_field2" />
<Value Type="Text">The value to filter against</Value>
</Eq>
</And>
</Where>
您可以将 <And>
标签嵌套在其他 <And>
和 标签中,以构建任意复杂的查询.
You can nest <And>
tags inside other <And>
and <Or>
tags to build arbitrarily complicated queries.
<Where>
<And>
<Eq>
<FieldRef Name="Internal_Name_of_field1" />
<Value Type="Text">The value to filter against</Value>
</Eq>
<And>
<Eq>
<FieldRef Name="Internal_Name_of_field2" />
<Value Type="Text">The value to filter against</Value>
</Eq>
<Eq>
<FieldRef Name="Internal_Name_of_field3" />
<Value Type="Text">The value to filter against</Value>
</Eq>
</And>
</And>
</Where>
元素中使用的确切语法可能因要比较的字段类型而异.
Type="Text"
适用于单行文本字段,但查找字段、日期字段和个人或组字段具有不同的语法.
The exact syntax used in the <Value>
element can vary depending on the type of field being compared against. Type="Text"
works for single line text fields, but lookup fields, date fields, and person or group fields have different syntax.
对于更高级的 CAML 查询,请注意 OrderBy
和 RowLimit
元素的位置:
For more advanced CAML queries, note the placement of OrderBy
and RowLimit
elements:
<View>
<Query>
<Where>
<Eq>
<FieldRef Name="Internal_Name_of_field" />
<Value Type="Text">The value to filter against</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name="Internal_Name_of_field" />
</OrderBy>
</Query>
<RowLimit>500</RowLimit>
</View>
这篇关于这是 Caml 查询的正确语法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!