Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to get the nth record (lets say 133rd) from the 1000 records (or unknown number of records) by using CAML query.

share|improve this question
add comment

5 Answers 5

You would need to figure out what qualifies the "133rd" record? Is is the ID (most cases, but not reliable as it does functions like in SQL database for auto-incremented column), is it the last modified date, created date, etc. What I've used to do was to use an OrderBy numeric column (0 decimals - so it integer) that I've always sorted after.

Once this is established you could even combine multiple clauses to get closer to your record, via OrderBy and Where, see here explanations http://weblogs.asp.net/uruit/archive/2010/06/15/how-to-add-new-filters-to-caml-queries-in-sharepoint-2007.aspx

Once you get your results back, just use LINQ to get your Last(), see here something similar Getting items from rows 4-8 in a Sharepoint list using CAML query?

Recomandations for large lists are to use in your Query any of the ContentIterator.ItemEnumerationOrderByID, ContentIterator.ItemEnumerationOrderByPath, or ContentIterator.ItemEnumerationOrderByNVPField in the OrderBy clause, see here for more http://msdn.microsoft.com/en-us/library/ee558807(v=office.14)

share|improve this answer
add comment

as said in above reply you can get specific no. of records using RowLimit. TO get nth record only you can use "ID" field to get specific reocrd.

i.e Where ID = "your number"

before firing query to retrive the nth make sure list contains n no. of records

Regards, Ketan

share|improve this answer
    
@Ketan03... wow thats great. Here ID means row number? can you please provide me better link to learn CAML –  Mihir Aug 9 '12 at 6:32
    
@Mihir you can download the U2U CAML builder tool from google and you can easily generate the query and use the same in your code. If above answered has helped please do mrk it as "Useful". –  Ketan03 Aug 9 '12 at 7:04
    
Just to point out this will only provide you with the correct result if no list item has ever been deleted from the list. –  Robert Kaucher Jun 13 '13 at 19:42
add comment

You could use RowLimit

<View>
 <RowLimit>133</RowLimit>
 <Query>
   <OrderBy>
     <FieldRef Name='aField' Ascending='False' />
   </OrderBy>
  <Query>
</View>
share|improve this answer
    
this will give upto 133 records right!! I want to display only one 133rd record. –  Mihir Aug 9 '12 at 6:31
    
Thats true, I thought you didn't have a unique identifier to go after. If you have ofc use Where Identifier eq 133 –  Anders Aune Aug 9 '12 at 6:46
add comment

Do you have any kind of identifier of that record? If so, just use Where clausule to select 1 record.

If not, you should just specify some argument in Where clausule to filter records (if possible), use Order By (if needed) and of course use RowLimit set to value of "n" and then use linq to get .Last() item in result set.

Yes, you will get "n" results but if you have no specific identifier for your record there is no other option.

If you need more help, try to be more specific about your scenario - eg. why you need nth record.

share|improve this answer
add comment

The easiest answer would be:

list.Items[132]

But I doubt you accept it ;)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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