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

Optional Parameters in SQL


neilmusgrove

Recommended Posts

Hi i am using IReport/Jasper Reports and I have mastered inserting parameters into the SQL. Can anyone tell me if it is possible to insert optional parameters into the SQL that a user may or may not select

EG

 

SELECT * FROM CAT {WHERE USERSELECTION = 1}

The problem with the only way i know at the moment is you would be left with the where clause even if the user did not use the parameter, i would expect you to be able to wrap the whole where clause in the property statement as above.

Thanks

 

Neil Musgrove

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 years later...

 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

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

  • 1 year later...

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