Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8131339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:04:04+00:00 2026-06-06T09:04:04+00:00

Today I came across the need to write a CAML query that uses WHERE

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:04:05+00:00Added an answer on June 6, 2026 at 9:04 am

    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

    WHERE Title IN ([Title1], [Title2],...[TitleN]) 
    

    for a List of 1-N string titles.

    private string _camlTitleEq = "<Eq>" +
                                     "<FieldRef Name=\"Title\" />" +
                                     "<Value Type=\"Text\">{0}</Value>" +
                                  "</Eq>";
    
    private XElement BuildOrClause(List<string> listItemTitles, int index)
    {
        //If we've reached the last item in the list, return only an Eq clause
        if (index == listItemTitles.Count - 1)
            return XElement.Parse(String.Format(_camlTitleEq, listItemTitles[index]));
        else
        {
            //If there are more items in the list, create a new nested Or, where
            //the first value is an Eq clause and the second is the result of BuildOrClause
            XElement orClause = new XElement("Or");
            orClause.Add(XElement.Parse(String.Format(_camlTitleEq, listItemTitles[index])));
            orClause.Add(BuildOrClause(listItemTitles, index + 1));
            return orClause;
        }
    }
    

    And you could use it like so:

    SPQuery query = new SPQuery();
    string titleIn = BuildOrClause(listItemTitles, 0).ToString(SaveOptions.DisableFormatting);
    
    query.Query = "<Where>" +
                      titleIn +
                  "</Where>";
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So today I just came across the 'live()' function that binds any future and
I came across some javascript at work today that used jQuery to fetch two
Today I came across a new CSS syntax that I have never seen before
Today I came across a very nasty problem, I need to make the front-end
I was reading something today and came across a statement that said: Lazy instantiation
Came across some code today that had a javascript array, made in php, using
I came across this Perl construct today: @foo = split(\n, $bar); That works well
I was looking over the ObjectProperty list today and came across the property TableIsFake
I came across some code today where a string is compared to two values
Today I came across an SQL statement that contains an element I've never seen.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.