Today I came across the need to write a CAML query that uses WHERE [Field] IN [Values]. I wanted to query a List where the list item’s Title was contained by a collection of strings. After receiving several errors running my query, I realized the In operator was new to SharePoint 2010 but I’m still in SharePoint 2007. As a result, the only option is to use multiple Or operators. Additionally an Or operator can only operate on 2 values at a time so this requires nested Or operators. How can you build such a query? See my solution below.
Share
I stumbled around a couple approaches before coming to this solution. I’m not sure of its scalability but it suits my needs so I thought I would share it. This recursive method should return the equivalent of
for a List of 1-N string titles.
And you could use it like so:
I hope this helps someone still working in SP 2007. Constructive feedback is welcome! If you’re in SharePoint 2010, use the already built in In Operator.