1

如果我的 Boolean 参数在JasperReports中为真,如何在 SQL 中添加 sub where 语句?
例如,我的 SQL 如下:

SELECT * FROM shops WHERE region = "Canada" ORDER BY name

如果我的参数为真,我想and isactive = 'Y'ORDER BY.
有谁知道我怎么能做到这一点?

4

3 回答 3

3

您可以添加附加参数以设置附加子句值。之后,您可以$P!{}在查询中使用语法。

样品:

<parameter name="param" class="java.lang.Boolean"/>
<parameter name="whereCond" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA[$P{param} ? " AND isactive='Y'" : ""]]></defaultValueExpression>
</parameter>
<queryString>
    <![CDATA[SELECT * FROM shops WHERE region='Canada' $P!{whereCond} ORDER BY name]]>
</queryString>
于 2012-10-15T06:45:58.093 回答
0

试试这个

select * from shops where region = "Canada"
AND isActive = CASE WHEN @var = 'True' then 'Y' ELSE isActive END
order by name
于 2012-10-15T03:48:37.190 回答
0

您可以直接在 SQL 中执行此操作

SELECT * FROM shops WHERE region = "Canada"
AND (@param <> `True` OR isActive = 'Y')
-----^^^^^^^^^^^^^^^^--<< Condition: Your param is not true------
ORDER BY name
于 2012-10-15T04:01:22.990 回答