javaiiispl Posted April 28, 2011 Share Posted April 28, 2011 Hi i am using IReport/Jasper Reports and the query for my situation is SELECT * FROM admin WHERE age=$P{age} and tnumber=$P{tno} Now i am getting input for both fields ie age and tnumber from user.In this case three possible condition occurscond1:- user may enter both age and tumber fieldscond2:- user may enter only agecond3:- user may enter only tnumber Above query is executed only if user enters both values, if user enters value for a single field it shows document has no pages. i want to satisfy all my condition(cond1,2,3) in a single query, Please help me by suggesting necessary query for above condition.. Thanks in advance.. Link to comment Share on other sites More sharing options...
gail26 Posted April 28, 2011 Share Posted April 28, 2011 I am new to iReport too and there might be better solution. Create another parameter that will construct your where clause. On this parameter it will check both parameter if they are null or not using conditional statement. Link to comment Share on other sites More sharing options...
javaiiispl Posted April 28, 2011 Author Share Posted April 28, 2011 I got solution for above issue.Just pass the query asSELECT * FROM admin WHERE ((age=$P{age} or $P{age} is null) and (tnumber=$P{tno} or $P{tno} is null))This will show necessary output. Link to comment Share on other sites More sharing options...
jpauze Posted April 28, 2011 Share Posted April 28, 2011 Glad you found a solution, Gail was on the right path as well and probably what I would have done. There are a ton of posts on the forum with how to use Parameters in SQL statements, both for doing parameter substitution as well as dynamically building SQL strings. Just do a search for Parameter and you can usually find what you are looking for. Here is a similar one I responded to recently and I know Matt has a number of posts on this topic.http://jasperforge.org/plugins/espforum/view.php?group_id=83&forumid=101&topicid=86329 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