0

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??

1
  • 1
    Not an answer, but CAMLEX.NET provides you an easy way to build such statements. See "Scenario 9. Dynamic filtering conditions" Commented Aug 15, 2012 at 9:17

1 Answer 1

1

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

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

and

Not IN CAML Query

Hope it helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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