cckozie Posted October 5, 2010 Share Posted October 5, 2010 I'm running iReport 3.7.1 and MySQL 5.1. I'm attempting to have the sort order set based on a parameter but can't get it to work. I've tried these 3 methods: 1) Use the parameter name in the ORDER BY clause. 2) Add the parameter to the SELECT clause with an alias and reference the alias in the ORDER BY clause. 3) Same as 2, but reference the alias in the Sort order (memory sort) dialog. In each case the report runs, but the records appear in the same order as if there were no ORDER BY or Sort order specified. If I paste the query for method 2 directly in the MySQL Query Browser or OpenOffice it does work properly. Any ideas? Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted October 5, 2010 Share Posted October 5, 2010 In the query, where you use a parameter as sql chunk (and not as value parameter), use the special syntax $P!{param}In 3.7.5 JasperReports has introduced the ability to sort records using variables, so just create a variable with an expression that uses your parameter, i.e.My_order (type String; calc: Nothing)exp: $P{my_param} == 1 ? $F{field1} : $F{field2}Giulio Link to comment Share on other sites More sharing options...
cckozie Posted October 6, 2010 Author Share Posted October 6, 2010 Thanks so much, and such an easy solution. You rock! 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