Contains Element (Query)
Searches for a string anywhere within a column that holds Text or Note field type values.
<Contains> <FieldRef Name = "Field_Name"/> <Value Type = "Field_Type"/> <XML /> </Contains>
The following example uses the Contains element within a string that is assigned to the Query property to return the titles of items where the Conference column value begins with "Morning" and contains "discussion session".
SPWeb mySite = SPControl.GetContextWeb(Context); SPList list = mySite.Lists["List_Name"]; SPQuery query = new SPQuery(); query.Query = "<Where><And><BeginsWith><FieldRef Name="Conference"/>" + "<Value Type="Note">Morning</Value></BeginsWith>" + "<Contains><FieldRef Name="Conference" /> <Value Type="Note">discussion session</Value>" + "</Contains></And></Where>"; SPListItemCollection myItems = list.GetItems(query); foreach (SPListItem item in myItems) { Label1.Text += item["Title"] + "<BR>"; }
Can the field value be a subset of the Value element?
I have tried a CAML query like the following:
<Where>
<Where>
<Contains>
<Value Type="Text">SomeDataHere</Value>
<FieldRef Name="Title" />
</Contains></Where>
Unfortunately, it doesn't work. Is there a reason why it shouldn't work this way?
Thanks
Unfortunately, it doesn't work. Is there a reason why it shouldn't work this way?
Thanks
- 1/20/2010
- h_chin
How to implement "ignore case" for Contain
I wanna implement a caml query like:
<where>
<Contains>
<FieldRef Name=\"Title\" />
<Value Type=\"Text\">
Key
</Value>
</Contains>
</where>
If i wanna ignore the case, ex. i wanna search all the items whose title contain "key" or "Key" or "KEY" or...
Does CAML support it?
PS: Same condition when i search "e" but i have many é,è,ê in my items.
- 10/9/2009
- JackieLee