There's a simple problem.
If you look at the docs.. there is another statement that you can use to wrap what you have called:
 
<dynamic prepend="WHERE">
if you add that instead of your 'where' it will be okay.
-Tim


From: Nilesh Bhattad [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 18, 2005 11:02 AM
To: [email protected]
Subject: Qns abt using <isNotEmpty/> inside <select/>

Hello,

 

I’m having some trouble while using <isNotEmpty/> node inside <select/>

 

Please take a look at below select statement.

 

     <select id="search" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">

          select ConsultantId, BlackListed, FirstName, LastName, HomeTelephone, EmailAddress, InterviewGrade, TotalYrsOfExp from Consultant where

          <isNotEmpty property="FirstName">FirstName like #FirstName#</isNotEmpty>

          <isNotEmpty property="LastName" prepend=" and ">LastName like #LastName#</isNotEmpty>

          <isNotEmpty property="ActiveInactive" prepend=" and ">ActiveInactive like #ActiveInactive#</isNotEmpty>

          order by FirstName, LastName

     </select>

 

The problem with this stmt is if only ActiveInactive is keyed in, the select stmt is resolved like below –

 

select ConsultantId, BlackListed, FirstName, LastName, HomeTelephone, EmailAddress, InterviewGrade, TotalYrsOfExp from Consultant where                                  and ActiveInactive like ?           order by FirstName, LastName

 

‘and’ is added in the stmt which makes it invalid query. How do I adjust the <isNotEmpty/> tags inside <select/> so that it will work for any combination?

 

Help, please !

 

~ Nilesh

Reply via email to