SharePoint 2010 / 2013 CAML In / Include Function

The <In> function is available in SharePoint 2010 /  2013 CAML query.
This works with similar functionality to the IN Function in sql. That is to say, that you can provide multiple values without having to use large blocks of <OR> functions.

The following query was working well:


   <Where>
                <In>
                                <FieldRef Name='UserID'/>
                                <Values>
                                                <Value Type='Number'>1</Value>
                                                <Value Type='Number'>2</Value>
                                                <Value Type='Number'>4</Value>
      </Values>
                </In>
   </Where>

You can also use the <In> function to query text values.

 
From this query you would receive items back where the UserID field was 1,2 or 4.

Taking this one step further I noticed it was not possible to embed the <In> function with an <Or> case:
   <Where>
       <Or>
            <In>
                <FieldRef Name='UserID'/>
                          <Values>
                                 <Value Type='Number'>2</Value>
                                 <Value Type='Number'>3</Value>
                          </Values>
           </In>
            <In>
               <FieldRef Name='SectionID'/>
                          <Values>
                                <Value Type='Number'>2</Value>
                                <Value Type='Number'>4</Value>
                          </Values>
             </In>     
       </Or>
   </Where>

The query above didnt work :(



Oh, and one thing to note. The <In> function was not returning the correct results through CAML query builder for me. However, this should work correctly through code!!!

Comments

  1. Hi Alexander ,

    Nice post,Thanks for sharing this information.





    Sharepoint Developers

    ReplyDelete
  2. Hi, I implemented the same query using instead of , it is working fine.

    ReplyDelete

Post a Comment

Popular Posts