0

I was wondering how to make a parameter accept several values in JasperReports' report and they are separated by commas. How to do this without using $P! and $X and no collection or list? Just in the WHERE clause or Parameter expression

Alex K
  • 22,315
  • 19
  • 108
  • 236
kimdasuncion12
  • 319
  • 2
  • 4
  • 17
  • `How to do this without using $P! and $X and no collection or list` - What is a reason of so strange limitation? Is it a test? :) – Alex K Jan 20 '17 at 09:13
  • `values are separated by commas` - The using of `$P!` is a good choice in this case – Alex K Jan 20 '17 at 09:15
  • No sir I was searching for ways to do this and I always see this ways on how to do this i was just wondering if its possible. I know there is a simple way to do this but I couldnt wrap my head around it. – kimdasuncion12 Jan 20 '17 at 09:17
  • 1
    You can add escaped quotes for every value and use `$P!`. Something like this:`$P{value}` = `'a', 'b'`, and expression will be: `WHERE attrName = $P!{value}`. It is a simplest way (if not to use `$X`) – Alex K Jan 20 '17 at 09:19
  • Possible duplicate of [JasperReports: Passing parameters to query](http://stackoverflow.com/questions/11871042/jasperreports-passing-parameters-to-query) – Alex K Jan 20 '17 at 09:21
  • where should i put this ? $P{value} = 'a', 'b' – kimdasuncion12 Jan 20 '17 at 09:23
  • I don't know how you are preparing the parameters values. In your code :) – Alex K Jan 20 '17 at 09:23
  • `$P{value} = 'a', 'b'` - It was a pseudo code. I mean that you should set such value to parameter. Don't worry it is not a JasperReports expression – Alex K Jan 20 '17 at 09:26
  • Do i have to put all the values or there what if there are hundred values? – kimdasuncion12 Jan 20 '17 at 09:28
  • If you have numeric values you can compare values by ranges, if it is string values you have to use `IN` (`WHERE attrName IN $P!{valuesSeparatedByComma}`). Do you know alternates if not to use subqueries? – Alex K Jan 20 '17 at 09:30
  • No sir it just names of classes i want my parameter to be able to accept multiple names of classes. These are the values of my classes are 'Iowa','Kongo','Tennessee' ... and my where clause looks like this. where (first.class = $P{Clss} or $P{Clss} = '') and displacement between $P{MinWeight} and $P{MaxWeight} – kimdasuncion12 Jan 20 '17 at 09:36
  • Please [edit](http://stackoverflow.com/posts/41759845/edit) your original question to add all required information (maybe with screenshots) - I don't understand the problem – Alex K Jan 20 '17 at 09:41

0 Answers0