0

I want to skip sharepoint items where 'location' field equals 'USA' and 'Id' equals 3

How can i do this with sharepoint CAML query?

I need something like NOT for this AND:

<And>
   <Eq><FieldRef Name='Location' /><Value Type='Text'>USA</Value></Eq>
   <Eq><FieldRef Name='Id' /><Value Type='Counter'>3</Value></Eq>
</And>
1

We can apply De Morgan's law here:

NOT(A && B) = NOT(A) || NOT(B)

meaning your query will look like:

<Or>
   <Neq><FieldRef Name='Location' /><Value Type='Text'>USA</Value></Neq>
   <Neq><FieldRef Name='Id' /><Value Type='Counter'>3</Value></Neq>
</Or>

There is no NOT CAML operator.

Cheers!

1

You can use <Neq> operator instead of <Eq> if you want them both to be not equal. So your query will look like this:

<And>
   <Neq><FieldRef Name='Location' /><Value Type='Text'>USA</Value></Neq>
   <Neq><FieldRef Name='Id' /><Value Type='Counter'>3</Value></Neq>
</And>
  • 1
    Your query is skipping only one item. But it's actually not perfectly clear if this is what Evgeny asked or not. In my opinion he wants to skip multiple items. – Norbert Dec 6 '12 at 11:30
  • 1
    This query skips all items that have the location equal to USA and the Id equal to 3. (That how I understood the question). – user3470 Dec 6 '12 at 11:34
  • 1
    Yes, but in your opinion, how many items in a Sharepoint list can have the same Id? Id usually is the OOTB Id field, which is autoincremented and has unique values. If it would have been any other field, you would be right. – Norbert Dec 6 '12 at 11:41
  • 1
    Yes I know I just answered what I think was asked. – user3470 Dec 6 '12 at 11:46

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.