3

I need to get the list items from SP 2010 SPList, having the below criteria:

get all the records/listitems whose ID value in between 100 and 110. What should be the CAMl query for matching the above criteria.i have tried the below , but unfortunately it didn't work. i dont have U2U2 CAML builder tool installed in my dev machine.Hence, i am not able to test this!

        <Query>
         <Where>
          <And>
            <Gt>
            <FieldRef Name='ID' />
            <Value Type='Number'>100</Value>
           </Gt>
           <Lt>
             <FieldRef Name='ID' />
           <Value Type='Number'>110</Value>
      </Lt>
       </And>
     </Where>
  </Query>
  • if you are using SSOM, you need to get rid of <Query> tags – Gautam Sheth Apr 12 '18 at 15:23
  • am using SPServices Lib, camlqueryoptions attribute, camlviewfields . and not using SSOM.. – userAZLogicApps Apr 12 '18 at 18:55
4

You want to use Geq and Leq to be inclusive. Since you are using the ID column the type is actually Counter.

<Query>
  <Where>
    <And>
      <Geq>
        <FieldRef Name='ID' />
        <Value Type='Counter'>100</Value>
      </Geq>
      <Leq>
        <FieldRef Name='ID' />
        <Value Type='Counter'>110</Value>
      </Leq>
    </And>
  </Where>
</Query>
  • i will try and revert here! – userAZLogicApps Apr 12 '18 at 13:20
  • Is it possible to get the numbers using IN operator , what i see is, after applying the above counter using geq and leq, some items were missing from the list. – userAZLogicApps Apr 18 '18 at 20:13
  • 1
    Do the items actually exist? If you are using foldering, the default is to only pull items at the root level so you'll have to use the RecursiveAll scope to get nested items. The in operator requires you provide the values (which would work, but a range makes a lot more sense for finding all values between values) – theChrisKent Apr 18 '18 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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