Do anyone know how to get item with most characters from a SP list using CAML query?


2 Answers 2


Add a calculated column to your list. Calculate the length of the field you want using LEN(Field) and return as number.

This then boils down to just querying the calculated column using CAML query. Orderby by descending and and set rowlimit as 1. You will get the item with the field with most characters.


My best guess is that with a simple query that's not possible.
Options are:

  1. Get all items with a not-null value, and then sort them out in the code. Not a very good idea if you have 100s of items.
  2. Add an event receiver on the list. Count the number of characters in the field you want from the ER when an item is added/updated, and store the value in a hidden (technical) column. Then, use a CAML query to get the top most item (by ordering on the hidden field + retrieve only one row).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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