SharePoint CAML Query AND/OR operators

user3586514 picture user3586514 · Apr 29, 2014 · Viewed 14.9k times · Source

I would appreciate any help on getting my CAML query to work. I have the following list:

| ID | Department | Status |

I am trying to get the query to return list items where ID=1, Department=Audit, and Status= "Stopped" OR "In Progress".

Can anyone please help?

Regards,

Answer

Vadim Gremyachev picture Vadim Gremyachev · Apr 29, 2014

Query:

<Query>
   <Where>
      <And>
         <Eq>
            <FieldRef Name='ID' />
            <Value Type='Counter'>1</Value>
         </Eq>
         <And>
            <Eq>
               <FieldRef Name='Department' />
               <Value Type='Choice'>Audit</Value>
            </Eq>
            <Or>
               <Eq>
                  <FieldRef Name='Status' />
                  <Value Type='Choice'>In Progress</Value>
               </Eq>
               <Eq>
                  <FieldRef Name='Status' />
                  <Value Type='Choice'>Not Started</Value>
               </Eq>
            </Or>
         </And>
      </And>
   </Where>
</Query>

Note: it is assumed that Department is a Choice field


I would recommend you to utilize the tool that will help you build your CAML Queries, for example U2U Caml Query Builder

enter image description here