0

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.

2 Answers 2

3

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

4
  • You beat my answer out by 40 seconds lol. So close. So close. Commented Feb 8, 2013 at 21:44
  • Thank you for the help once again. It's much appreciated.
    – E7AD
    Commented Feb 8, 2013 at 21:59
  • @rjcup3 you gotta be fast next time brother :P... Commented Feb 8, 2013 at 22:14
  • @E7AD here to help my friend! Commented Feb 8, 2013 at 22:15
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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