简体   繁体   English

CAML“不在”查询

[英]CAML “NOT IN” query

Is there a way to do something like "NOT IN" behavior in SharePoint 2010? 有没有办法在SharePoint 2010中执行“NOT IN”行为? I can easily implement IN behavior like that: 我可以像这样轻松实现IN行为:

<Where>
   <In>
      <FieldRef Name="ID"/>
      <Values>
         <Value Type="Counter">1</Value>
         <Value Type="Counter">2</Value>
         <Value Type="Counter">3</Value>
         <Value Type="Counter">4</Value>
         <Value Type="Counter">5</Value>
      </Values>
   </In>
</Where>

But is there a way to select all the values that DOES NOT IN Values enumeration? 但有没有办法选择所有值不在值列举?

Here is the USE CASE: I have a Lookup field with AllowMultipleValues = true, and I need to get all items from LookupList, which are not included into Lookup field 这是USE CASE:我有一个带有AllowMultipleValues = true的Lookup字段,我需要从LookupList获取所有项目,这些项目不包含在Lookup字段中

Thanks in advance! 提前致谢!

Starting from SharePoint 2010, there's the NotIncludes element that might work for you. 从SharePoint 2010开始,可能有适合您的NotIncludes元素。 From MSDN: 来自MSDN:

If the specified field is a Lookup field that allows multiple values, specifies that the Value element is excluded from the list item for the field that is specified by the FieldRef element. 如果指定的字段是允许多个值的查找字段,则指定从FieldRef元素指定的字段的列表项中排除Value元素。

Template: 模板:

<NotIncludes>
    <FieldRef Name="Field_Name" />
    <Value Type="Field_Type" />
    <XML />
</NotIncludes>

To get the opposite behavior of 'In', you have to make a nested 'Neq' query. 要获得“In”的相反行为,您必须进行嵌套的“Neq”查询。 'NotIncludes' could be substituted for or combined with 'Neq' if you are dealing with a Lookup Field with multiple values . 如果您正在处理具有多个值的查找字段,则“NotIncludes”可以替换为“Neq”或与“Neq”组合使用。

<Query>
    <Where>
        <And>
            <And>
                <Neq>
                    <FieldRef Name="ID" /><Value Type="Counter">5</Value>
                </Neq>
                <Neq>
                    <FieldRef Name="ID" /><Value Type="Counter">13</Value>
                </Neq>
            </And>
            <And>
                <NotIncludes>
                    <FieldRef Name="children" /><Value Type="Lookup">20</Value>
                </NotIncludes>
                <NotIncludes>
                    <FieldRef Name="children" /><Value Type="Lookup">32</Value>
                </NotIncludes>
            </And>
        </And>
    </Where>
</Query>

If you want more variables then more nesting needs to be done. 如果您想要更多变量,则需要进行更多嵌套。 Have fun. 玩得开心。

I think the Not equal option would be the best way to build this CAML query 我认为不等于选项将是构建此CAML查询的最佳方式

Maybe this (didn't test this, so bear with me) 也许这个(没试过这个,所以请耐心等待)

<Query>
   <Where>
     <And>
       <Neq>
          <FieldRef Name="ID" /><Value Type="Counter">1</Value>
       </Neq>
       <Neq>
          <FieldRef Name="ID" /><Value Type="Counter">2</Value>
       </Neq>
       <Neq>
          <FieldRef Name="ID" /><Value Type="Counter">3</Value>
       </Neq>
     </And>
   </Where>
</Query>

You should have a look at the available Comparison Operators 您应该查看可用的比较运算符

  • Contains 包含
  • BeginsWith 开始于
  • Eq, Equal 等式,等于
  • Neq, Not equal Neq,不等于
  • Gt, Greater than Gt,大于
  • Lt, Less than 不,小于
  • Geq, Greater than or equal to Geq,大于或等于
  • Leq, Less than or equal to Leq,小于或等于
  • DateRangesOverlap, Compare dates in recurring event with specified value DateRangesOverlap,将周期性事件中的日期与指定值进行比较
  • IsNotNull IsNotNull
  • IsNull 一片空白

The closest I've come is to use <NotIncludes></NotIncludes> , but for some reason is does not work the same way as <In></In> . 我最接近的是使用<NotIncludes></NotIncludes> ,但由于某种原因,它与<In></In> In <In> I can use <Values> . <In>我可以使用<Values> With <NotIncludes> it looks like you can only specify one value. 使用<NotIncludes>看起来您只能指定一个值。 The rest will have to be <Or> ed in, similar to <Neq> . 其余部分必须<Or>编入,类似于<Neq>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM