0
Good afternoon, I have an SQL query as code below where I have 3 filters, these filters use the clause Where, and e and but if one of the filters is blank the value returned is also blank.
How can I do this treatment, either in the database or directly in the JSP file?
SELECT DISTINCT DECODE (initcap(PP.OVERALL_HEALTH), '', '/itg/images/statusreport/NA.gif', '/itg/images/statusreport/' || DECODE(UPPER(PP.OVERALL_HEALTH), 'GREEN', 'Verde', initcap(PP.OVERALL_HEALTH)) || '.gif' ) SAUDE_PROGRAMA_ICONE, PP.CONTAINER_NAME NOME_PROGRAMA, HD.VISIBLE_PARAMETER1 TIPO_CLIENTE, HD.VISIBLE_PARAMETER32 DIRETOR, P.NAME
FROM PGM_PROGRAMS PP
INNER JOIN KCRT_REQ_HEADER_DETAILS HD ON HD.REQUEST_ID = PP.PGM_REQUEST_ID
INNER JOIN KCRT_FG_PFM_PROGRAM FP ON FP.REQUEST_ID = PP.PGM_REQUEST_ID
INNER JOIN FM_FINANCIAL_SUMMARY FS ON PP.FINANCIAL_SUMMARY_ID = FS.FINANCIAL_SUMMARY_ID
INNER JOIN PFM_PORTFOLIO_CONTENTS PC ON FS.FINANCIAL_SUMMARY_ID = PC.FINANCIAL_SUMMARY_ID
INNER JOIN PFM_PORTFOLIOS P ON PC.PORTFOLIO_ID = P.PORTFOLIO_ID
WHERE HD.PARAMETER1 = 'CORPORATIVO'
AND HD.PARAMETER32 IN '100427'
AND P.NAME IN (select p.name as portfolio from pfm_portfolios p
start with p.portfolio_id in '34006'
connect by prior p.portfolio_id = p.parent_portfolio_id)
Thanks for the answer, but if I tested it correctly it does not meet my need because it needs to bring exactly what is in the filter and so it brings as if it were an OR, then ends up not filtering, although it solves the value return empty problem.
– Guilherme Montagnani
@Guilhermemontagnani if you put the parentheses in the right place will certainly filter. This behavior you described only occurs if the parentheses are in the wrong place or if you do not use
AND
between the parameters– Sorack
The expression was as follows: WHERE (HD.PARAMETER1 = 'CORPORATE' AND HD.PARAMETER1 = HD.PARAMETER1) AND (HD.PARAMETER32 = '100427' OR HD.PARAMETER32 is = HD.PARAMETER32)
– Guilherme Montagnani
@Guilhermemontagnani you applied wrong what I answered. It would look something like this:
WHERE (:PARAMETER1 = '' OR HD.PARAMETER1 = :PARAMETER1) AND (:PARAMETER32 = '' OR :PARAMETER32 = HD.PARAMETER32)
– Sorack
I understand, now I can not do the test, but I will save the query and as soon as possible answer if solved my problem. Thanks in advance for the help!
– Guilherme Montagnani
Good afternoon brother, I thank you for your help but it really didn’t work, the query returns empty.
– Guilherme Montagnani