Jump to content
We've recently updated our Privacy Statement, available here ×

Condition in WHERE clause based on PARAMETER


anji.viper
Go to solution Solved by mlopez_1,

Recommended Posts

Hello guys,

I would like to know whether it is possible to use a CASE condition in my WHERE clause using a parameter.

For example, I have a query which takes the ID of the organisation as parameter:

SELECT org_name, org_addressFROM t_organisationWHERE id_org = $P{ID_ORGANISATION}[/code]

But it turns out that I have some organisations which have multiple rows in the table t_organisation and I want to use all their IDs in the query using the parameter..

What I want is something like this:

SELECT org_name, org_addressFROM t_organisationWHERE id_org in (    CASE when $P{ID_ORGANISATION} = '123'     then ('1231','1232','1233','1234')     else $P{ID_ORGANISATION}     end)[/code]

Any help would be greatly appreciated..

Thanks!

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I think this is an SQL question.

Try putting:

CASE WHEN $P{ID_ORGANISATION} = '123'     THEN ('1231','1232','1233','1234')     ELSE $P{ID_ORGANISATION}END[/code]

As a field and wrap this select with other select you can use for where clause for this field

SELECT *FROM(SELECT ..       CASE WHEN $P{ID_ORGANISATION} = '123'            THEN ('1231','1232','1233','1234')            ELSE $P{ID_ORGANISATION}       END AS FIELD_1FROM ..)WHERE FIELD_1 ......[/code]

Regards,

Mariano

Link to comment
Share on other sites

  • Solution

Yes, you are right.

Then, the only thing i know to do is this:

WHERE id_org IN $P{PARAMETER_LIST}[/code]

And use PARAMETER_LIST as java.util.List and its Default Value Expression as:

$P{ID_ORGANISATION}.equals("123") ?    Arrays.asList("1231","1232","1233","1234") :    Arrays.asList($P{ID_ORGANISATION})[/code]

This should work.

Mariano

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...