CAML "NOT IN" query

Viewed 16420

Is there a way to do something like "NOT IN" behavior in SharePoint 2010? I can easily implement IN behavior like that:

<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

Thanks in advance!

4 Answers

The closest I've come is to use <NotIncludes></NotIncludes>, but for some reason is does not work the same way as <In></In>. In <In> I can use <Values>. With <NotIncludes> it looks like you can only specify one value. The rest will have to be <Or>ed in, similar to <Neq>.

Related