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>

2 Answers 2

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>
4
  • 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. Commented Dec 6, 2012 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). Commented Dec 6, 2012 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. Commented Dec 6, 2012 at 11:41
  • 1
    Yes I know I just answered what I think was asked. Commented Dec 6, 2012 at 11:46

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.