CAML contains following operators:
- Eq: equal
- Geq: greater than or equal
- Gt: greatoer then
- Leq: lower than or equal
- Lt: lower than
- BeginsWith
- Contains
- IsNull
- IsNotNull
- Includes (new in SharePoint 2010)
- In (new in Sharepoint 2010)
I never tried to use the “IN” Operator. I thought most of my other friends do not know about this. So here is IN” Operator CAML Query.
<Where>
<In>
<FieldRef Name='ID' />
<Values>
<Value Type='Counter'>5</Value>
<Value Type='Counter'>6</Value>
<Value Type='Counter'>7</Value>
</Values>
</In>
</Where>
And My C# Window Application Code
private void button2_Click(object sender, EventArgs e)
{
using (SPSite _site = new SPSite("http://home"))
{
using (SPWeb oWebsite = _site.OpenWeb())
{
SPList spList = oWebsite.Lists.TryGetList("Custom List");
if (spList != null)
{
SPQuery qry = new SPQuery();
qry.Query =@"<Where>
<In>
<FieldRef Name='ID' />
<Values>
<Value Type='Counter'>5</Value>
<Value Type='Counter'>6</Value>
<Value Type='Counter'>7</Value>
</Values>
</In>
</Where>";
qry.ViewFields = "<FieldRef Name='ID' />";
SPListItemCollection listItems = spList.GetItems(qry);
MessageBox.Show(listItems.Count.ToString());
}
}
}
}
Hope you like this post.
Good info. Lucky me I ran across your blog by accident (stumbleupon).
ReplyDeleteI have book-marked it for later!
My blog post ; website
Thank you:-)
ReplyDelete