You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by ro...@wipro.com on 2006/04/12 06:49:22 UTC

Help required to write a query

Hi,



I am using the below code to retrieve user details from a table:




<select id="searchUser" parameterClass="searchCriteria"
resultClass="searchCriteria" resultMap="userMap2">

select * from USR_BASIC_INFO   

  <dynamic prepend="where">  

   <iterate property="userlist" conjunction="or"> USR_ID=#userlist[]#  

     and(

     <isParameterPresent>    

     <isEqual property="operator" compareValue="and">     

      <isNotNull prepend="and" property="username"
removeFirstPrepend="true"> USR_NAME=#username# </isNotNull>     

       <isNotNull prepend="and" property="phonenumber"
removeFirstPrepend="true"> PHONE_NUMBER=#phonenumber# </isNotNull>

      </isEqual> 

     </isParameterPresent> 

        

     <isParameterPresent>   

      <isEqual property="operator" compareValue="or">


        <isNotNull prepend="or" property="username"
removeFirstPrepend="true"> USR_NAME=#username# </isNotNull>

        <isNotNull prepend="or" property="phonenumber"
removeFirstPrepend="true"> PHONE_NUMBER=#phonenumber# </isNotNull>

      </isEqual>

     </isParameterPresent>     

         )

    </iterate>   

   </dynamic>

</select>



But during execution, I am getting the following error, i.e "and" is
appended twice:



select * from USR_BASIC_INFO               where          USR_ID=?
and(
USR_NAME=?                     and PHONE_NUMBER=?
)      or USR_ID=?       and(
and USR_NAME=?                 and PHONE_NUMBER=?
)      or USR_ID=?          and(
and USR_NAME=?                 and PHONE_NUMBER=?
)      or USR_ID=?       and(
and USR_NAME=?                 and PHONE_NUMBER=?
)   . 

Can you please tell how the query is to be written?



Regards,

Rohini






The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com