Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have two list(subject, subjectcategory).

subject(ID,Title,CategoryId)

subjectcategory(ID,Title)

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

SELECT     ID, Title
FROM         dbo.SubjectCategory
WHERE     (ID NOT IN
                      (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>" +
                      "</Neq>";

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
  BuildOrClause
  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 +
      "</Where>";

Is there any way for it??

share|improve this question
1  
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

1 Answer 1

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

http://stackoverflow.com/questions/341039/does-not-contain-in-caml

and

Not IN CAML Query

Hope it helps :)

share|improve this answer

Your Answer

 
discard

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.