Do anyone know how to get item with most characters from a SP list using CAML query?
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.
- 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.
- 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).