Using Parameters in FROM part of a SQL query

0

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'

j.seyfried@xiiix.de's picture
Joined: Apr 25 2019 - 12:08am
Last seen: 3 days 17 hours ago

Have you tried using the open and close brace {} so your parameter will be -

SELECT * FROM $P{language}

luked - 2 weeks 2 days ago

Sorry, thats just a mistake in transcribing it here. I've tried it with $P{language} but instantly when adding this from the list of parameters it underlines this part red and explains when hovering over it "no viable alternative at input '$P{language}' "

j.seyfried@xiiix.de - 2 weeks 1 day ago

2 Answers:

0

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

santhosh.devadurga's picture
Joined: Nov 9 2014 - 10:25pm
Last seen: 4 days 18 hours ago
0

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)

j.seyfried@xiiix.de's picture
Joined: Apr 25 2019 - 12:08am
Last seen: 3 days 17 hours ago
Feedback
randomness