Search code examples
sharepointsharepoint-2007caml

What is the limit of nested OR's in a CAML Query?


From the question 'SQL IN equivalent in CAML' I learned that SharePoint 2010 has a SQL "IN" equivalent for CAML. Also that the 2007 version does not support this. The OP solved this by nesting a bunch of OR statements to achieve the same result. I tested this and the nesting indeed does the magic, but...

In my case I'm getting items from a list with around a 1000 items. I dynamically create a statement with all the IDs in nested OR-blocks for my CAML-query. I didn't worry about the big number of nested blocks as this is what MSDN states about the OR-element:

Occurrences: Minimum: 0, Maximum: Unbounded.

and:

This element can be nested inside other Or and And elements. The server supports unlimited complicated queries.

When I call the GetListItems-method from the SharePoint 2007 built-in webservice, I get following error:

Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown. Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.

My code is written correctly because I tested the same code with only 5 nested Or-elements and the result is as expected. My question is: what IS the limit of nested Or-elements? I cannot find this anywhere as Microsoft claims this is unlimited.

Thanks in advance!


Solution

  • For those facing the same problem. I went for a search on SharePoint.StackExchange.com and found the following question:

    One of the answers points to this website:

    The person discovered that 500 items was too much but that a batch of 300 worked fine. So I tried this and this also works for me. So for anyone that faces the same problem, this might be the solution. :)