im做一个jasper报告,该报告按多个参数过滤,这些参数是使用where子句中的case语句可选的。如果未输入参数,我希望结果集满足其他参数,则还应包含null。
我在where子句中做了一个case语句,除了最后一个条件,我得到了想要的结果。当参数为空时,我希望其他条件b满足结果,包括where子句
中其他条件满足的空记录SELECT
cert.ice_certificate_date_issued AS "START_DATE",
cert.ice_current_license_expiry AS "END_DATE",
--licence_type,
ib.name AS "SHOP",
cert.ice_license_fee AS "SUPERMARKETPRICE",
dist.name AS "DISTRICT",
,iba.ice_price)
,0) AS "ACTIVITY_PRICE",
(select nvl(sum(taxamt),0) from c_ordertax where c_order_id = cert.c_order_id) AS "TAXAMT"
FROM icp_certificate cert
LEFT JOIN c_order ord ON cert.c_order_id = ord.c_order_id
LEFT JOIN icp_business ib ON cert.ice_foreign_trx_entity_id =
ib.icp_business_id
LEFT JOIN c_bpartner cbp ON cert.c_bpartner_id = cbp.c_bpartner_id
LEFT JOIN c_bpartner_location cbpl ON cert.c_bpartner_id =
cbpl.c_bpartner_id
LEFT JOIN icp_district dist ON cbpl.ice_district_id =
dist.ice_district_id
LEFT JOIN c_location loc on ib.c_location_id = loc.c_location_id
LEFT JOIN icp_business_activity_link ibal ON ib.icp_business_id =
ibal.icp_business_id
LEFT JOIN icp_business_activity iba ON ibal.icp_business_activity_id =
iba.icp_business_activity_id
WHERE
cert.ad_client_id = 1000555 AND
cert.ad_org_id = 2010520 AND
cert.icp_certificate_status = '01' AND
cert.isactive = 'Y' AND
cert.ice_certificate_type = '0051' AND
cert.ice_currentcertificate = 'Y' AND
cert.icp_certificate_date_issued BETWEEN '01-JAN-19' AND '23-MAY-19' AND
ib.ICp_District_ID = CASE WHEN 0>0 THEN 46445665 else ib.ICp_District_ID
END
-我希望else部分包括ib.ICp_District_ID为空的记录
其他条件内所有内容的返回结果,包括区号为空的记录
答案 0 :(得分:0)
在我看来,您可以使用
.
.
.
(ib.ICp_District_ID = CASE
WHEN 0>0 THEN 46445665
else ib.ICp_District_ID
END
OR
ib.ICp_District_ID IS NULL)
可以简化为
NVL(ib.ICp_District_ID, -99) = NVL(ib.ICp_District_ID, -99)
因为CASE表达式将始终返回ib.ICp_District_ID
。只需省略完全检查ib.ICp_District_ID
的条件,就可以进一步简化它,因为它总是可以满足的。 (当然,假设您打算将条件WHEN 0 > 0
保留在CASE表达式中,该条件始终为FALSE,因此它将始终落入ELSE。)
好运。