SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two list(subject, subjectcategory).



I want to create a CAML query for SharePoint that does something like this

SELECT     ID, Title
FROM         dbo.SubjectCategory
                      (SELECT     CategoryID
                        FROM          dbo.Subject))

Edit I use this code

should return the equivalent of

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

for get list of title :

private string _camlTitleEq = "<Neq>" +
                         "<FieldRef Name=\"Title\" />" +
                         "<Value Type=\"Text\">{0}</Value>" +

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]));
  //If there are more items in the list, create a new nested Or, where
  XElement andClause = new XElement("And");
  andClause.Add(XElement.Parse(String.Format(_camlTitleEq, listItemTitles[index])));
  andClause.Add(BuildOrClause(listItemTitles, index + 1));
  return andClause ;

and for set query

 SPQuery query = new SPQuery();
 string titleIn = BuildOrClause(listItemTitles, 0).ToString(SaveOptions.DisableFormatting);

 query.Query = "<Where>" +
          titleIn +

Is there any way for it??

share|improve this question
Not an answer, but CAMLEX.NET provides you an easy way to build such statements. See "Scenario 9. Dynamic filtering conditions" – Janis Veinbergs Aug 15 '12 at 9:17

I dont know if this will help you but here are some links that should lead you in the right direction:


Not IN CAML Query

Hope it helps :)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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