none
caml query like operator RRS feed

  • Question

  • HI friends,

    Can any body know how to write "LIKE" operator  using  CAMLQUery.
     give me some sample code

    Thanks

    kiran
    Thursday, September 25, 2008 1:58 AM

Answers

  • 1st of all you dont need to use % operator. 

    LIKE operator acts like you need to search any where in string like %o% so in your case you are looking to search in title if it begins with o letter. so you will use BegingsWith operator in caml query. there is a sample in above link for BeginsWith as well.

    any way, one thing i can see here that you are trying to use Computed column here for LIKE operator while as you know LIKE is only used for TEXT or NOTE type field and same is for BeginsWith operator. However you can go ahead and test it in your scenario if it does not work with Value type computed , then put value type TEXT.


    Thursday, September 25, 2008 1:49 PM

All replies

  • use the CONTAINS in CAML Query where clause, it works like operator.

    check this article and it has example for you as well

     

    http://www.a2zdotnet.com/View.aspx?id=90

    Thursday, September 25, 2008 2:27 AM
  • Hi Thanks for you reply
     
    for exmaple sample sql is : select distinct title_id  from titles where title_id like '" + prefixText + "%' "

    <Query>
       <Where>
          <Contains>
             <FieldRef Name='
    title_id ' />
             <Value Type='Computed'>o</Value>
          </Contains>
       </Where>
    </Query>

    wher to put "%" end with?

    thanks

    kiran
    Thursday, September 25, 2008 2:39 AM
  • 1st of all you dont need to use % operator. 

    LIKE operator acts like you need to search any where in string like %o% so in your case you are looking to search in title if it begins with o letter. so you will use BegingsWith operator in caml query. there is a sample in above link for BeginsWith as well.

    any way, one thing i can see here that you are trying to use Computed column here for LIKE operator while as you know LIKE is only used for TEXT or NOTE type field and same is for BeginsWith operator. However you can go ahead and test it in your scenario if it does not work with Value type computed , then put value type TEXT.


    Thursday, September 25, 2008 1:49 PM