mariarita Posted February 27, 2012 Share Posted February 27, 2012 Hi,I've this query:SELECT DISTINCT CARTELLA."COGNOME" AS CARTELLA_COGNOME, CARTELLA."NOME" AS CARTELLA_NOME, CARTELLA."DATA_NASC" AS CARTELLA_DATA_NASC, COMUNE_NASC."DESCRIZIONE" AS COMUNI_DESCRIZIONE, COMUNI_RES."DESCRIZIONE" AS COMUNI_DESCRIZIONE_RES, ANAGRA_C."INDIRIZZO" AS ANAGRA_C_INDIRIZZO, INTPRE."PRE_DES_PREST" AS INTPRE_PRE_DES_PREST, CARTELLA."N_CARTELLA" AS CARTELLA_N_CARTELLAFROM "SINSNT_TEST"."COMUNI" COMUNE_NASC INNER JOIN "SINSNT_TEST"."CARTELLA" CARTELLA ON COMUNE_NASC."CODICE" = CARTELLA."COD_COM_NASC" INNER JOIN "SINSNT_TEST"."ANAGRA_C" ANAGRA_C ON CARTELLA."N_CARTELLA" = ANAGRA_C."N_CARTELLA" INNER JOIN "SINSNT_TEST"."INTPRE" INTPRE ON CARTELLA."N_CARTELLA" = INTPRE."PRE_CARTELLA" INNER JOIN "SINSNT_TEST"."COMUNI" COMUNI_RES ON ANAGRA_C."CITTA" = COMUNI_RES."CODICE"I want create a report with the parameter n_cartella, i.e I want to choose the n_cartella and to visualize the data relating to that n_carella.What should I do to add the parameter?ThanksMariarita Link to comment Share on other sites More sharing options...
cbarlow3 Posted February 27, 2012 Share Posted February 27, 2012 So in the previous query, you had a line in your WHERE clause that said AND CARTELLA.N_CARTELLA=2It sounds like you instead want the user to be able to enter 2 (or whatever number they like) and have the report select based on that. In iReport, make sure you have the "Report Inspector" pane open. In that tree, you should see "Parameters" with either a + or - sign next to it. If it's a + sign, click on the + to expand that part of the tree so you can see the parameters that iReport creates for you automatically (REPORT_CONNECTION, REPORT_TIME_ZONE, etc.). Now if you right-click on "Parameters" you can "Add Parameter". iReport will automatically add a new parameter to the tree with a name of "parameter1" that is of Parameter Class java.lang.String. If the data you are comparing to is actually an Integer, for example, then you need to change the parameter class. Left click the parameter "parameter1" in the Report Inspector tree if it is not already selected. Now look in the Properties pane. Change the name of the parameter from parameter1 to n_cartella (or whatever name you like), and use the Parameter Class dropwdown to the class to java.lang.Integer, or whichever data type agrees with the data in the CARTELLA.N_CARTELLA field in your database. Leave the "Use as a prompt" checkbox checked. You can assign a Default Value Expression or not.Now, in your query and in any expressions you use, iReport has a syntax where parameter names are surrounded by $P{}. So you change the line that has a hardcoded number 2 in your WHERE clause to instead read:AND CARTELLA.N_CARTELLA=$P{n_cartella}That should be enough to get iReport to prompt you for the parameter and use it for comparison when you are running the report from the iReport preview. If your actual runtime environment is eventually JasperReports Server, then when you deploy your report to the server repository, you will also have to set a property on the report to make it prompt, and you'll have to define an Input Control that has the same name and data type as your parameter.Carl Link to comment Share on other sites More sharing options...
mariarita Posted February 27, 2012 Author Share Posted February 27, 2012 thanks a lot, you're very kind Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now