ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgsweb <sgs...@websulting.com>
Subject iBatis Dynamic Query
Date Fri, 14 Mar 2008 17:37:42 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Tw Cen MT">Hi,<br>
<br>
I have an issue that I cannot find a solution with iBatis.&nbsp; Here's the
scenario.<br>
<br>
I have two tables, say "TBL1" and "TBL2".&nbsp; TBL1 has two fields say
"TBL1_FLD1" and TBL1_FLD2" and TBL2 has one field, say "TBL2_FLD1".<br>
<br>
I want to create a dynamic query such that if either property for
TBL1_FLD1 or TBL1_FLD2 exist then include the table TBL1 in the FROM
clause.<br>
<br>
e.g.,<br>
<br>
<small><font face="Courier New, Courier, monospace">SELECT
TBL2.TBL2_FLD1<br>
FROM<br>
&nbsp;&nbsp;&nbsp; TBL2<br>
&nbsp;&nbsp;&nbsp; &lt;isNotEmpty prepend="," property="propertyForTbl1_fld1
OR
propertyForTbl1_fld2"&gt;TBL1&lt;/isNotEmpty&gt;<br>
WHERE<br>
&nbsp;&nbsp;&nbsp; some clause</font></small><br>
<br>
That is, I only want to include "TBL1" in the FROM clause only if
either one of the property for fld1 or fld2 is not empty.&nbsp; Now, I can
do the following:<br>
<br>
<small><font face="Courier New, Courier, monospace">SELECT
TBL2.TBL2_FLD1<br>
FROM<br>
&nbsp;&nbsp;&nbsp; TBL2<br>
&nbsp;&nbsp;&nbsp; &lt;isNotEmpty prepend=","
property="propertyForTbl1_fld1"&gt;TBL1&lt;/isNotEmpty&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;isNotEmpty prepend=","
property="propertyForTbl1_fld2"&gt;TBL1&lt;/isNotEmpty&gt;<br>
WHERE<br>
&nbsp;&nbsp;&nbsp; some clause</font></small><br>
<br>
But, this could put the TBL1 in the FROM clause twice.<br>
<br>
Any help is greatly appreciated.<br>
<br>
thanks,<br>
sgs.<br>
</font>
</body>
</html>

Mime
View raw message