DB2数据库,怎样实现下面的动态SQL的查询结果?多谢! 10
SELECTXXMODLASD1MODL,SUM(XXQTY1)ASD1QTYFROMCSPLIB_CHN.CTXX01WHEREXXDSTY=#{cmpnId}ANDX...
SELECT XXMODL AS D1MODL, SUM(XXQTY1) AS D1QTY
FROM CSPLIB_CHN.CTXX01
WHERE XXDSTY = #{cmpnId}
AND XXDSTR = #{corpCd}
<if test="carLine != ''">
AND XXMODL LIKE '${carLine}%'
</if>
<if test="exColor != ''">
AND XXEXCL = #{exColor}
</if>
GROUP BY XXMODL 展开
FROM CSPLIB_CHN.CTXX01
WHERE XXDSTY = #{cmpnId}
AND XXDSTR = #{corpCd}
<if test="carLine != ''">
AND XXMODL LIKE '${carLine}%'
</if>
<if test="exColor != ''">
AND XXEXCL = #{exColor}
</if>
GROUP BY XXMODL 展开
展开全部
easy ,把if换成 OR .
<if test="carLine != ''">
AND XXMODL LIKE '${carLine}%'
</if>
变成 OR (carLine != '' and XXMODL like '${carLine}%' )
<if test="carLine != ''">
AND XXMODL LIKE '${carLine}%'
</if>
变成 OR (carLine != '' and XXMODL like '${carLine}%' )
追问
你的意思是把上面的代码写成下面这样吗?
--carLine和exColor是输入参数,用?代替:
SELECT * FROM CSPLIB_CHN.CTXX01
WHERE ...
OR (? != '' and XXMODL like '?%' )
OR (? != '' AND XXEXCL = ? )
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询