I am fairly experienced with CAML Queries, but this one has me stuck. I need some help in structuring the query's logic. What I need is to return every record that that contains two words across two columns.
我对CAML查询很有经验,但这个让我感到困惑。我在构造查询逻辑时需要一些帮助。我需要的是返回两列中包含两个单词的每条记录。
Example (return these):
示例(返回这些):
- Column1: word1, Column2: word2. //Return this record
- Column1: word2, Column2: word1. //Return this record
- Column1: word2 word1, Column2: (empty). //Return this record
- Column1: (empty), Column2: word2 word1. //Return this record
Column1:word1,Column2:word2。 //返回此记录
Column1:word2,Column2:word1。 //返回此记录
Column1:word2 word1,Column2 :(空)。 //返回此记录
Column1 :(空),Column2:word2 word1。 //返回此记录
Example (do not return these):
示例(不要返回这些):
- Column1: (empty), Column2: word1. // Do not return this record
- Column1: word1, Column2: (empty). // Do not return this record
- Column1: (empty), Column2: word2. // Do not return this record
- Column1: word2, Column2: (empty). // Do not return this record
- Column1: (empty), Column2: (empty). // Do not return this record
Column1 :(空),Column2:word1。 //不要返回此记录
Column1:word1,Column2 :(空)。 //不要返回此记录
Column1 :(空),Column2:word2。 //不要返回此记录
Column1:word2,Column2 :(空)。 //不要返回此记录
Column1 :(空),Column2 :(空)。 //不要返回此记录
To put the logic in sudo-code:
if( ("word1" appears in 'Column1' OR "word1" appears in 'Column2') AND ("word2" appears in 'Column1' OR "word2" appears in 'Column2') )
I have tried different variations of queries, but they do not return desirable results. For example, the one below will always return a record if word1 appears in Column1 even if word2 does not appear anywhere.
将逻辑放在sudo-code中:if((“word1”出现在'Column1'或“word1”出现在'Column2'中)AND(“word2”出现在'Column1'或“word2”出现在'Column2')我尝试了不同的查询变体,但它们没有返回理想的结果。例如,如果word1出现在Column1中,则下面的那个将始终返回记录,即使word2没有出现在任何地方。
<Query>
<Where>
<Or>
<Contains>
<FieldRef Name="Column1"/><Value Type="Text">word1</Value>
</Contains>
<And>
<Contains>
<FieldRef Name="Column2"/><Value Type="Text">word1</Value>
</Contains>
<Or>
<Contains>
<FieldRef Name="Column1"/><Value Type="Text">word2</Value>
</Contains>
<Contains>
<FieldRef Name="Column2"/><Value Type="Text">word2</Value>
</Contains>
</Or>
</And>
</Or>
</Where>
P.S. I am in SharePoint 2007 using SPServices
附:我在使用SPServices的SharePoint 2007中
1 个解决方案
#1
Thanks to spevilgenius on spservices.codeplex.com, here is what worked for me:
感谢spservices.codeplex.com上的spevilgenius,这对我有用:
<And>
<Or>
<Contains>
<FieldRef Name="Column1"/><Value Type="Text">word1</Value>
</Contains>
<Contains>
<FieldRef Name="Column2"/><Value Type="Text">word1</Value>
</Contains>
</Or>
<Or>
<Contains>
<FieldRef Name="Column1"/><Value Type="Text">word2</Value>
</Contains>
<Contains>
<FieldRef Name="Column2"/><Value Type="Text">word2</Value>
</Contains>
</Or>
</And>
Link to discussion: https://spservices.codeplex.com/discussions/637384
链接到讨论:https://spservices.codeplex.com/discussions/637384
#1
Thanks to spevilgenius on spservices.codeplex.com, here is what worked for me:
感谢spservices.codeplex.com上的spevilgenius,这对我有用:
<And>
<Or>
<Contains>
<FieldRef Name="Column1"/><Value Type="Text">word1</Value>
</Contains>
<Contains>
<FieldRef Name="Column2"/><Value Type="Text">word1</Value>
</Contains>
</Or>
<Or>
<Contains>
<FieldRef Name="Column1"/><Value Type="Text">word2</Value>
</Contains>
<Contains>
<FieldRef Name="Column2"/><Value Type="Text">word2</Value>
</Contains>
</Or>
</And>
Link to discussion: https://spservices.codeplex.com/discussions/637384
链接到讨论:https://spservices.codeplex.com/discussions/637384