Hi all,
I am currently trying to create a report based that displays the number of pages that I am printing per month. My SQL query is pulling all the data in my database since recording of the printer page count started. Creating a variable which calculates the total is easy enough, but is there a way that a variable can select specific data from the sql query and use that in a sum calculation, i.e. just this month's data? Could I use a sql quert within the variable expression is some way?
Thanks!
2 Answers:
new java.text.SimpleDateFormat("MM").Format($F{fieldDate}) == new java.text.SimpleDateFormat("MM").Format(new java.util.Date()) ? $F{field you want to sum} : 0
might be a more simpler way to do this, but it's the "IF" stmt basically...
Thanks for the help.
I changed the variable expression field to:
new java.text.SimpleDateFormat("MM").Format($F{sampletime})==new java.text.SimpleDateFormat("MM").Format(new java.util.Date()) ? $F{samplevalue} : 0
but it then produces the following error. Error filling print... Error evaluating expression : Source text : new java.text.SimpleDateFormat("MM").Format($F{sampletime})==new java.text.SimpleDateFormat("MM").Format(new java.util.Date()) ? $F{samplevalue} : 0
Setting up the file resolver... net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : Source text : new java.text.SimpleDateFormat("MM").Format($F{sampletime})==new java.text.SimpleDateFormat("MM").Format(new java.util.Date()) ? $F{samplevalue} : 0 at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:259) at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:580) at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:179) at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:789) at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1478) at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:125) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:942) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:841) at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247) at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:877) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot find function Format in object java.text.SimpleDateFormat@9a0. at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535) at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3563) at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3582) at org.mozilla.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:3646) at org.mozilla.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2186) at org.mozilla.javascript.gen.c120._c0(expression:0) at org.mozilla.javascript.gen.c120.call(expression) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003) at org.mozilla.javascript.gen.c120.call(expression) at org.mozilla.javascript.gen.c120.exec(expression) at net.sf.jasperreports.compilers.JavaScriptEvaluator.evaluateExpression(JavaScriptEvaluator.java:304) at net.sf.jasperreports.compilers.JavaScriptEvaluator.evaluateEstimated(JavaScriptEvaluator.java:285) at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:246) ... 13 more
Print not filled. Try to use an EmptyDataSource...
I'm fairly new to java and sql so it may be that I've just gotten something really simple wrong. Apolgies if that's the case.