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