Jump to content
We've recently updated our Privacy Statement, available here ×

How to use optional parameters


javaiiispl

Recommended Posts

 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 occurs
cond1:- user may enter both age and tumber fields
cond2:-  user may enter only age
cond3:- 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

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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

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

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