Jump to content
Changes to the Jaspersoft community edition download ×

How to set SQL query to the dataset dynamically?


Recommended Posts


I have 5 sql queries and I am designing a report which have one dropdown control and that dropdown contains name of those queries.

Now, when user selects any one option from dropdown then accordingly that query should be set to the dataset and table should display data according to the result of that dataset.

Can anyone please guide me how this can be achieved?

Please note I am using Jaspersoft Studio for report development.

Thanks in advance.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic


first of all, I'd like to mention all the SQL queries must return identical set of fields, in your scenario.

In order to achieve the requirements, you could use $P!{} syntax : 


The idea is to create an additional hidden parameter which uses selected by user option from drop-down list to specify according query, like

IF($P{Parameter1}.equals("Q1"),"select orderid as id from orders",IF($P{Parameter1}.equals("Q2"),"select shipvia as id from orders","select 1 as id"))

Then, the report dataset query should be like


Find attached sample report that demonstrates the idea.

Hope, this helps.

Best regards,

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...