Hi, I am trying to create a dynamic query which uses a parameter. I would like to have the query look like: SELECT tableA.field1, tableA.field2, table A.field3 FROM tableA, tableB WHERE tableA.field3 = 3 and tableA.field4 = tableB.field4 ORDER BY 2 What I would like to do is have the data in red ("tableB" in the FROM clause, and the row: "and tableA.field4 = tableB.field4") be added only if a certain parameter contains a value of x. I added a parameter called REPORT_FIELD4_NAME which has a value of: $P{REPORT_FIELD1}.equals( "x" ) ?: "and tableA.field4 = tableB.field4" : "" meaning that if parameter REPORT_FIELD1 = x then add the row "and tableA.field4 = tableB.field4" to the query. and I added another parameter called REPORT_FIELD4_NAME which has a value of: $P{REPORT_FIELD1}.equals( "x" ) ? ", tableB" : "" and then wrote the query in this format: SELECT tableA.field1, tableA.field2, table A.field3 FROM tableA $P!{REPORT_FIELD4_NAME_TABLE} WHERE tableA.field3 = $P!{REPORT_FIELD4_NAME} ORDER BY 2 but this doesn't work. A few quesitons: 1. Is this the correct way to write a dynamic query? Can I write this in the query designer in the iReports or do I have to enter it manually in the jrxml file? 2. I added the parameters under the Parameters section in the Report Inspector, and they are both input parameters. So when I run the report the user is prompted for input for these parameters. Could this be what is causing the problem? Also, is there a way to make these parameters not for input? 2. Can I use a parmeter in the FROM clause like I did? By the way, when I tried to use a parameter only in the where clause it did not work either. 3. Can I use a partameter in the ORDER BY clause? If so how do I do this? Thanks Post Edited by ak10 at 12/19/2010 15:21