0

I have 3 fields(Fname,Email,Phone)

<viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
 <FieldRef Name='ID' /> \
                       </ViewFields> \
  </viewFields> \
  <query> \
   <Query> \
<Where> \
<Contains> \
     <FieldRef Name='Title','Fname' /> \
         <Value Type='Text'>"+qry+"</Value> \
  </Contains> \
  </Where> \
</Query> \
  </query> \
   </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";
0

2 Answers 2

1

Try this

<Query>
   <Where>
      <And>
         <Contains>
            <FieldRef Name='Title' />
            <Value Type='Text'>Qassas</Value>
         </Contains>
         <Contains>
            <FieldRef Name='Fname' />
            <Value Type='Text'>ww</Value>
         </Contains>
      </And>
   </Where>
</Query>
<ViewFields>
   <FieldRef Name='Fname' />
   <FieldRef Name='Email' />
   <FieldRef Name='Phone' />
</ViewFields>
0

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);

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.