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'm trying to write a CAML query with the following parameters and I'm not having much luck. It should be simple enough but I can't figure it out.

WHERE (X) EQUALS (A or B) And C

I'm hoping someone might be able to point me in the right direction. Thanks in advance.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

You should write query like below:

<Where>
   <And>
      <Or>
         <Eq><FieldRef Name="X" /><Value Type="Text">A</Value></Eq>
         <Eq><FieldRef Name="X" /><Value Type="Text">B</Value></Eq>
     </Or>
     <Eq><FieldRef Name="X" /><Value Type="Text">C</Value></Eq>
  </And>
</Where>

Also, try using some CAML Query Builders that will help you:
CAML Query Tools suggested by Microsoft
Caml Query Helper
U2U CAML Query Builder

share|improve this answer
    
You beat my answer out by 40 seconds lol. So close. So close. –  RJ Cuthbertson Feb 8 '13 at 21:44
    
Thank you for the help once again. It's much appreciated. –  E7AD Feb 8 '13 at 21:59
    
@rjcup3 you gotta be fast next time brother :P... –  Arsalan Adam Khatri Feb 8 '13 at 22:14
    
@E7AD here to help my friend! –  Arsalan Adam Khatri Feb 8 '13 at 22:15
add comment

The basic structure you want will be something like:

<Query>
   <Where>
      <And>
         <Or>
            <Eq>
                A
            </Eq>
            <Eq>
                B
            </Eq>
         </Or>
         <Eq>
             C
         </Eq>
      </And>
   </Where>
</Query>

A, B, and C will each be a <FieldRef /> and <Value></Value> set.

Hope that makes sense.

Edit

As Arsalan suggested, Karine Bosch's U2U Caml Builder for 2003 and 2007 is available here. It makes building the structure of more complex queries a lot easier.

To use it with SP 2010 (unsure about 2013) you can connect via web services as seen here.

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