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

2 Answers 2

up vote 1 down vote accepted

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!

share|improve this answer
add comment

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