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

Using Parameters in FROM part of a SQL query


j.seyfriedxiiix.de

Recommended Posts

I've got a datasource where the data is stored in tables with language prefixes and I'd like to let the user select the language as a parameter. 

I tried to handover the language prefix as a parameter in the FROM part of my SQL query, but Jasper Report won't execute that. Are there any other ways? 

Here's what I tried so far:

SELECT * FROM $P(language)

If it would be possible to join the parameter with a fix string that would be even greater:

SELECT * FROM $P(language) + '_article_view_full'

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

I would suggest you to create a one more parameter like,

Parameter Name: LanguageValue

Class: String

Expression: $P{language} + "_article_view_full"  ( better handle the null or empty value cases for $P{language} )

Then query like,  SELECT * FROM $P!{languageValue} ( ! should be there )

Let me know if you have any concerns

Link to comment
Share on other sites

Thanks Santhosh, I've tried it the way you suggested and I receive the following errors:

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:1. de cannot be resolved to a variable                value = de; //$JR_EXPR_ID=0$                        <>2. de cannot be resolved to a variable                value = de; //$JR_EXPR_ID=0$                        <>3. de cannot be resolved to a variable                value = de; //$JR_EXPR_ID=0$                        <>3 errors.    at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:206)    at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:286)    at com.jaspersoft.studio.editor.preview.view.control.ReportController.compileJasperDesign(ReportController.java:478)    at com.jaspersoft.studio.editor.preview.view.control.ReportController.access$8(ReportController.java:463)    at com.jaspersoft.studio.editor.preview.view.control.ReportController$1.run(ReportController.java:381)    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)[/code]

 

 

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