Jump to content
Changes to the Jaspersoft community edition download ×

how to display columns from different tables in one single report template?


mgbrillo

Recommended Posts

can i use just one template to display columns from a specified table name?

using the sample database with iReports 4.5.1.

we have tables: ADDRESS and ORDERS

I wanted to create a template where the user selects "ADDRESS" in the parameter prompt, the report will display the values for the columns available ONLY for ADDRESS.

on the same report template, if the user selects "ORDERS", the report will display values for the columns available ONLY for ORDERS.

thanks in advance.



Post Edited by mgbrillo at 03/27/2012 22:15
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello,

 

you should put: <printWhenExpression><![CDATA[$P{your_parameter} == "ADDRESS"]]></printWhenExpression> in the header and in the detail of your Address column (in the static text and in the text fields)

 

and the same with "ORDERS"

 

Good luck

 

AP

Link to comment
Share on other sites

in my SQL, i have it as: SELECT * FROM $P!{TABLE_NAME}

if in the report i have these valid fields from 'ADDRESS' as: ID, FIRSTNAME, LASTNAME, STREET and CITY, then this works.

but then when i add fields valid for 'ORDERS' (for example, i wanted to show: ORDERID, SHIPNAME, SHIPADDRESS and SHIPCITY), how to i set these?

i was thinking of having all of these fields (for both ADDRESS and ORDERS) in the template but if in the parameter prompt, i enter ADDRESS, supposedly it should JUST show the ID, FIRSTNAME, LASTNAME, STREET and CITY fields (via Print When Expression = $P{TABLE_NAME}.equals{"ADDRESS"}, but i'm getting an error saying "Unknown column name: ORDERID" (and all the column name valid ONLY for ORDERS.

is there a way to revise the SQL statement that will show only valid column names for the 'entered' table name? something like:

SELECT (*if parameter value is "ADDRESS", then show column names here based on the parameter value) OR (*if parameter value is "ORDERS", then show the column names here based on the parameter value WHERE $P!{TABLE_NAME}

this way the SQL statement will show only the valid column names based on the entered parameter value and NOT read the other column names from the other table(s).

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