You can always use u2u caml builder to construct caml query.
Btw here is a sample code how you can create dynamic query.
SPList listPricing_Brandfamily = web.Lists["Pricing_Brandfamily"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Where>"
+ "<And> "
+ "<Eq> "
+ " <FieldRef Name='BrandFamily_ID' /> "
+ " <Value Type='Lookup'>" + brandFamilyID.ToString() + "</Value> "
+ " </Eq> "
+ " <And> "
+ " <Eq> "
+ " <FieldRef Name='CountryID' /> "
+ " <Value Type='Lookup'>" + countryID.ToString() + "</Value> "
+ " </Eq> "
+ " <Eq> "
+ " <FieldRef Name='PackSize' /> "
+ " <Value Type='Number'>" + packSize.ToString() + "</Value> "
+ " </Eq> "
+ " </And> "
+ " </And> "
+ " </Where>";
SPListItemCollection collItem = listPricing_Brandfamily.GetItems(oQuery);
if (collItem.Count > 0)
{
return true;
}
return false;
You can also user stringbuider
for better readability.
SPList list = web.Lists["RevisionChildWorkFlow"];
SPQuery oQuery = new SPQuery();
StringBuilder query = new StringBuilder();
query.Append("<Where>");
query.Append("<And>");
query.Append("<Eq>");
query.Append("<FieldRef Name='RevisionID' />");
query.Append("<Value Type='Lookup'>" + priceProposalID.ToString() + "</Value>");
query.Append("</Eq>");
query.Append("<And>");
query.Append("<Eq>");
query.Append("<FieldRef Name='UserGroup' />");
query.Append("<Value Type='Text'>" + userGroupTypes.ToString() + "</Value>");
query.Append("</Eq>");
query.Append("<Eq>");
query.Append("<FieldRef Name='Author' LookupId='TRUE'/>");
query.Append("<Value Type='Integer'>" + CurrentUserID + "</Value>");
query.Append("</Eq>");
query.Append("</And>");
query.Append("</And>");
query.Append("</Where>");
oQuery.Query = query.ToString();
SPListItemCollection collItem = list.GetItems(oQuery);