0

I have a query that I've written like this:

<Where>
   <Or>
     <Neq><FieldRef Name='Status'></FieldRef><Value Type='Text'>Created</Neq>
     <Neq><FieldRef Name='Status'></FieldRef><Value Type='Text'>Updated</Neq>
   </Or>
</Where>

Just 1 Neq works (outside of an OR) - but when I do both in an OR - I'm getting back more results than I would expect and some where status is "Updated" (as per value above).

What I am trying to do is:

Get all items where status is not Created or Updated.

Is my logic correct? Is my CAML correct? Thanks in advance!

2

Using U2U CAML Builder (on a tasks list), I get a CAML statement that looks like this, substitute values as needed both for the value type and for the values themselves:

<Query>
   <Where>
      <And>
         <Neq>
            <FieldRef Name='Status' />
            <Value Type='Choice'>Deferred</Value>
         </Neq>
         <Neq>
            <FieldRef Name='Status' />
            <Value Type='Choice'>Not Started</Value>
         </Neq>
      </And>
   </Where>
</Query>

Or based on your information provided:

<Query>
   <Where>
      <And>
         <Neq>
            <FieldRef Name='Status' />
            <Value Type='Text'>Created</Value>
         </Neq>
         <Neq>
            <FieldRef Name='Status' />
            <Value Type='Text'>Updated</Value>
         </Neq>
      </And>
   </Where>
</Query>
2

I think you want an And. Get all items where status not equal to Created and status not equal to Updated.

  • Tried the And operator too, unfortunately same result. – JL01 Oct 26 '11 at 16:11
  • @JL01, I reckon @Rob Windsor is right: you need And logic here. And plus, where is an error in the CAML itself: closing </Value> tags are missed. – Andrey Markeev Oct 26 '11 at 16:58
  • @Omlin - aha I see it now! Couldn't spot it, thanks for the comment! – JL01 Oct 26 '11 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.