SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My question is regarding retrieving a value from a sharepoint list. Basically I have a list with some data. One of the fields in the list is a text field with numbers.

So what i want to do, i want to retrieve the highest number from that field ... how can i do that most practical and with best approach?

This will be done programmatically.

Of course i couuld do a loop through all the items, but i would like to avoid looping, is there a better way?

Thanks in advance.

share|improve this question
up vote 2 down vote accepted

Programatically use SPQuery and in your caml query use the OrderBy Node


<Query><OrderBy><FieldRef Name="yourcolumn" Ascending="True" /></OrderBy></Query>

You can also set the RowLimit property of SPQuery to 1 to make it more efficient

Hope this helps

UPDATE: As Nadeem Yousuf mentioned on another answer, this will not work with a text field, so might need to consider changing the type of this column (if possible?)

share|improve this answer
nah, can't change it directly ... so no any other practical approaches for it? – Shkipper Dec 19 '12 at 13:29
did you know that if the data are all number you could change the type without losing any data?. Unfortunately I am not aware of another way to do it without looping though all the items. Wonder if you can use this guys and casting to an int in the lambda query – Renzo Dec 19 '12 at 13:35

Had the field in question been a Number field, I would have done Order By desc on that and put the RowLimit of SPQuery to 1. But I am not sure whether Ordery By clause will work here as yours is a text field containing numbers.

share|improve this answer

Your Answer


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.