How to use concatenation function in JSP file

Asked

Viewed 52 times

0

Good afternoon.

I have an SQL query with 3 Where clauses, but I need to activate them only when the values are filled in.

How can I make the jsp file recognize that for example field 1 is filled in, then concatenate the first Where, if fields 1 and 3 are filled in, concatenate the 1st Where and the 3rd and so on?

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
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 = '<c:out value="${TIPO_CLIENTE}" />'
AND HD.PARAMETER32 = '<c:out value="${DIRETOR}" />'
AND P.NAME IN (select p.name as portfolio from pfm_portfolios p
start with p.portfolio_id in '<c:out value="${nome1.PORTFOLIO_ID}" />' 
connect by prior p.portfolio_id = p.parent_portfolio_id)

1 answer

-2


You can try to identify which fields are filled in before performing the query, depending on which fields are filled in, you mount your query.

  • Good morning. In practice, how would that be? Because it needs to be dynamic, you will always have available to fill two fields, but not necessarily they will be filled, but the file I use would be one.

  • You can use an IF by checking if the variable is doing if(variable1.isEmpty() && variable2.isEmpty()){ //statements if the two are varios } , and depending on the result Voce executes a different sql

Browser other questions tagged

You are not signed in. Login or sign up in order to post.