Understanding Dynamic queries




How To Write Dynamic CAML :

While writing CAML query, you must understand the architecture how it works.


It is pretty simple. You just have to do logical AND/OR operators.


Any operator must have 2 conditions to combine and test.

SCENARIO 1 : This is 1 Operator use with 2 conditions


<Or>
     <Eq>
          <FieldRef Name='Status' />
          <Value Type='Text'>StatusVal1</Value> 
     </Eq>
     <Eq>
          <FieldRef Name='Status' />
          <Value Type='Text'>StatusVal2</Value>
     </Eq>
</Or>      

SCENARIO 2 : This is 2 Operators use with 2 conditions From scenario 1 we got operator now along with that we will add another operator.

<And>
   <Or>
      <Eq>
          <FieldRef Name='Status' />
          <Value Type='Text'>StatusVal1</Value>   
      </Eq>
      <Eq>
          <FieldRef Name='Status' />
          <Value Type='Text'>StatusVal2</Value>    
      </Eq>
   </Or>
   <Eq>
      <FieldRef Name='Status' />
      <Value Type='Text'>StatusVal3</Value>
   </Eq>
</And>

Here if you notice, <OR> is having two conditions inside it. and that makes 1 condition for outer <And>, so we added another condition block parallel to <OR> operator. Hence 2 conditions are available for <AND>.



Likewise you can build n number of nested conditions.


PS: If you have only 1 condition, it will not require any operator.

49 views0 comments

Recent Posts

See All

In this blog we will see how to export a list in excel using server side object model. First block we will retrieve all items from the list. This can be done in several ways. You can get all items wit