Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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>
share|improve this answer
add comment

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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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