mateen83 Posted November 6, 2009 Share Posted November 6, 2009 My report uses the following query. select folio_number from unit_account uawhere ua.folio_number in (1,2,3,4,5,6,7,8,9,10,11)order by to_number(ua.folio_number)How can i represent the IN clause in the above SQL as a parameter. If i use a string it adds a ' ' before and after and the query will not execute. How can i use an in clause so i can provide multiple account numbers in the same parameter. Link to comment Share on other sites More sharing options...
iancr01 Posted November 6, 2009 Share Posted November 6, 2009 Try using $P!{parameter name} instead of just $P{parameter name}. Link to comment Share on other sites More sharing options...
iancr01 Posted November 6, 2009 Share Posted November 6, 2009 You can also use: select ... where $X{IN, colname, parameter name} "parameter name" is a parameter of type Collection or array. Link to comment Share on other sites More sharing options...
mateen83 Posted November 7, 2009 Author Share Posted November 7, 2009 Its worked using $P!{parameter_name} . Thanks for your help Link to comment Share on other sites More sharing options...
shatad0101 Posted June 23, 2011 Share Posted June 23, 2011 iancr01Wrote: You can also use: select ... where $X{IN, colname, parameter name} "parameter name" is a parameter of type Collection or array. Hi, Today I was trying to use parameter in where clausesuch as-- select emp_salary,last_namefrom employeeswhere emp_id in ($p{id1},$p{id2}) but i m getting error so how tofigure out this problem plz help me Is it possible to do such a thing with iReport and JasperReport ? Link to comment Share on other sites More sharing options...
cbarlow3 Posted June 24, 2011 Share Posted June 24, 2011 Yes, but your syntax is off. Here is a line from a SQL command in one of my reports:WHERE $X{ IN, NOTE_TYPE.DESCRIPTION, AlertTypeList } AND ...This particular line is making sure that the DESCRIPTION field of a note type record (we enforce that this field is unique, as we use this description instead of a code to identify the different note types available on our system) is one of the descriptions stored in a user-selected list parameter called $P{AlertTypeList}. With the $X{} syntax, the word "IN" is the name of the function (the other choice is "NOT IN"). It does not appear in quotation marks or with a $, etc. The second argument is the field name. It must be a fieldname, which is why it doesn't require $F{} around it...that would be redundant. Similarly, the third argument must be a parameter, so you don't put $P{} around the name.So far, so good, but what kind of parameter is this? In your example, it looked like you had the user enter ID1 and ID2. That's not how $X{ IN } is used. Instead, it expects your parameter to be of type java.util.Collection or java.util.List. These list parameters can be a bit of a pain to fill out when testing in iReport, but they can be really slick when you deploy to JasperServer and create an input control to go along with your list/collection parameter. Specifically, when you create the input control, you can make the type of that control be either "Multi-select List of Values" if you're going to have the user choose from multiple pre-defined values or you can use "Multi-select Query" if you want to give them a multi-select selection box where the options are pulled from the database in real time. I use the multi-select queries a lot so the user can choose from customized lists without me hardcoding choices that they are bound to modify outside my control.Carl Link to comment Share on other sites More sharing options...
texonic2003 Posted August 22, 2012 Share Posted August 22, 2012 cbarlow3Wrote: Yes, but your syntax is off. Here is a line from a SQL command in one of my reports: WHERE $X{ IN, NOTE_TYPE.DESCRIPTION, AlertTypeList } AND ... This particular line is making sure that the DESCRIPTION field of a note type record (we enforce that this field is unique, as we use this description instead of a code to identify the different note types available on our system) is one of the descriptions stored in a user-selected list parameter called $P{AlertTypeList}. With the $X{} syntax, the word "IN" is the name of the function (the other choice is "NOT IN"). It does not appear in quotation marks or with a $, etc. The second argument is the field name. It must be a fieldname, which is why it doesn't require $F{} around it...that would be redundant. Similarly, the third argument must be a parameter, so you don't put $P{} around the name. So far, so good, but what kind of parameter is this? In your example, it looked like you had the user enter ID1 and ID2. That's not how $X{ IN } is used. Instead, it expects your parameter to be of type java.util.Collection or java.util.List. These list parameters can be a bit of a pain to fill out when testing in iReport, but they can be really slick when you deploy to JasperServer and create an input control to go along with your list/collection parameter. Specifically, when you create the input control, you can make the type of that control be either "Multi-select List of Values" if you're going to have the user choose from multiple pre-defined values or you can use "Multi-select Query" if you want to give them a multi-select selection box where the options are pulled from the database in real time. I use the multi-select queries a lot so the user can choose from customized lists without me hardcoding choices that they are bound to modify outside my control. Carl Code:Hi friends,I need to check following scenario in WHERE condition.lets say I am passing 4 parameters from my application like Start_Date, EmpNo, Name, Gender. I may pass one parameter or two or else as user selected. then I need WHERE condtion as follows,if Start_date passed but others are not then SQL quary should as.... Select * from tblemployee WHERE Start_date =$P{St_Date} & if both Start_date and EmpNO passed but others are not then SQL quary should as.... Select * from tblemployee WHERE Start_date=$P{St_Date} AND EmpNo= $P{Emp_No}can someone help me with a sample. Link to comment Share on other sites More sharing options...
tcoultas Posted February 11, 2015 Share Posted February 11, 2015 I just want to say that Carl's approach worked like a charm. AND, it ran the query in an optimized manner unlike the "where FOO in $P!{variable}" syntax. Sub second return vs. 16 second return. Sweet! 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