You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by onlyforfun <ch...@gmail.com> on 2008/07/30 07:50:04 UTC
how do generate a correct dynamic sql
I wrote a dynamic select statement like this:
<select id="area_SelectCustomize" parameterClass="area_query_model"
resultMap="area_Result" >
SELECT * FROM [dbo].[area]
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="type">
[type] = #type#
</isNotNull>
<isNotNull prepend="AND" property="keyword">
<isNotEmpty prepend="AND" property="keyword">
(
[code] LIKE '%$keyword$%'
OR [name] LIKE '%$keyword$%'
OR [remark] LIKE '%$keyword$%'
)
</isNotEmpty>
</isNotNull>
</dynamic >
</select>
when i pass parameters (type=1,keyword="new") to this statement, i expect
the result sql like this:
SELECT * FROM [dbo].[area] WHERE [type] = ? AND ( [code] LIKE '%new%' OR
[name] LIKE '%new%' OR [remark] LIKE '%new%')
but from the log file, i found the result is:
SELECT * FROM [dbo].[area] WHERE [type] = ? ( [code] LIKE '%new%' OR
[name] LIKE '%new%' OR [remark] LIKE '%new%')
The prepend "AND" is missing.
Is there anything wrong with my select statements? How can i get the result
i needed?
Thanks!
--
View this message in context: http://www.nabble.com/how-do-generate-a-correct-dynamic-sql-tp18726503p18726503.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.