CAML查询查找参数不存在的记录?

发布于 2024-08-12 05:29:01 字数 1128 浏览 3 评论 0原文

我有一个包含多个字段的共享点列表。看起来,当其中一条记录上的字段留空时,当我使用 CAML 查询查询列表时,该字段上缺少该属性。

是否可以编写一个查询来返回不包含此属性的记录?

示例:

id Employee Title description
-------------------------
1  Jeff  Person1 
2  Bob  Person2
3  Charles Person3
4    Person4
5    Person5

是否有任何方法可以查询此记录以仅返回 id 4 和 5 的记录,因为它们将名称字段留空?

我尝试了以下操作:

System.Text.StringBuilder xmlQuery = new StringBuilder();
xmlQuery.Append("<Query>");        
xmlQuery.Append("   <Where>");        
xmlQuery.Append("       <IsNull>");            
xmlQuery.Append("           <FieldRef Name=\"Employee Title\" />");           
xmlQuery.Append("       </IsNull>");        xmlQuery.Append("   </Where>");        
xmlQuery.Append("</Query>");        XmlNode query = new XmlDocument();          
query.InnerXml = xmlQuery.ToString();

但是这些记录中当然不存在该属性,因此不会返回任何内容

提前致谢!


编辑

名称中的任何空格替换为x0020后,查询将起作用

xmlQuery.Append("           <FieldRef Name=\"Employee_x0020_Title\" />");

I have a sharepoint list which has several fields. It seems that when a field is left blank on one of the records - that attribute is missing on the field when I query the list using a CAML Query.

Is it possible to write a query to return the records which do not contain this attribue?

Example:

id Employee Title description
-------------------------
1  Jeff  Person1 
2  Bob  Person2
3  Charles Person3
4    Person4
5    Person5

Is there any way to query this to only return records with id 4 and 5 because they have left the name field blank?

I tried the following:

System.Text.StringBuilder xmlQuery = new StringBuilder();
xmlQuery.Append("<Query>");        
xmlQuery.Append("   <Where>");        
xmlQuery.Append("       <IsNull>");            
xmlQuery.Append("           <FieldRef Name=\"Employee Title\" />");           
xmlQuery.Append("       </IsNull>");        xmlQuery.Append("   </Where>");        
xmlQuery.Append("</Query>");        XmlNode query = new XmlDocument();          
query.InnerXml = xmlQuery.ToString();

But of course the attribute doesn't exist in those records, so nothing is returned

Thanks in advance!


Edit

The query works after replacing any spaces in the Name with x0020

xmlQuery.Append("           <FieldRef Name=\"Employee_x0020_Title\" />");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小嗷兮 2024-08-19 05:29:01

如果字段值缺少一个或多个字段,应该不会有任何问题,这是正常现象并且应该可以工作。但是您必须在查询中进行的一项更改是删除外部查询标记,请使用以下查询,您应该可以开始了。

<Where>       
<IsNull>           
<FieldRef Name="Name" />       
</IsNull>   
</Where>

There should not be any issue if a field value is missing one or more fields, it is just normal and should work. But one change you will have to do in the query is to remove the outer query tag please use the below query and you should be good to go.

<Where>       
<IsNull>           
<FieldRef Name="Name" />       
</IsNull>   
</Where>
变身佩奇 2024-08-19 05:29:01

这是一个不太可能的情况,但是您的“名称”列实际上在列表中名为“标题”吗?

FieldRefs 期望字段的内部名称 AFAIK

This is a longshot, but is your "Name" column actually named "Title" within the list?

FieldRefs expect the internal name of the field AFAIK

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文