Jump to content
Changes to the Jaspersoft community edition download ×

How to loop query results in JasperReports and to print single value based on a condition


dusandevic

Recommended Posts

Hi All,

Let's say the query is as follows:

SELECT customer_id, customer_name, metric_name, metric_description, target_value, real_valueFROM customers_overviewWHERE customer_id = $P{customer_id}AND reporting_year = 2019[/code]

It'll give me a few rows, one per each metric_name, e.g. AVAILABILITY, TRAFFICOB, STORAGEDB, TRAFFICCW etc. All metric values delivered as a query result are related to this customer.

In JasperStudio I already have a kind of "written in stone" report with the following hardcoded table items: Availability of the platform (%), Total database storage (GB) etc. So I don't want to use table nor list to dynamically render all the rows as available in the query result.

My question is how to display the $F{real_value} of the row where metric_name is STORAGEDB next to the label 'Total database storage (GB)' in the report. Please consider my query will return many rows.

In pseudo-code I need something like this:

foreach(rows as row){   print row.metric_name == "STORAGEDB" ? row.real_value : "";}[/code]

... and such loop to repeat for each and every item I have hardcoded on my report.

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Not sure about your question. JasperReports will loop through all rows in the query.

If you just want to enter a condition to print $F{real_value} when $F{metric_name}.equals("STORAGEDB", you can just enter a ternary operator in the Expression.

$F{metric_name}.equals("STORAGEDB") ? $F{real_value} : ""

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