{"id":2724,"date":"2022-08-30T15:27:15","date_gmt":"2022-08-30T15:27:15","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/08\/jasperreports-constant-string-passed-to-subreport-gets-a-null-value-when-evalueted-with-p-in-the-sql-query-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:27:15","modified_gmt":"2022-08-30T15:27:15","slug":"jasperreports-constant-string-passed-to-subreport-gets-a-null-value-when-evalueted-with-p-in-the-sql-query-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/jasperreports-constant-string-passed-to-subreport-gets-a-null-value-when-evalueted-with-p-in-the-sql-query-collection-of-common-programming-errors\/","title":{"rendered":"JasperReports: Constant string passed to subreport gets a null value when evalueted with P!{} in the SQL-query-Collection of common programming errors"},"content":{"rendered":"<p><strong>In short:<\/strong><\/p>\n<p>I&#8217;m passing a constant string to a subreport, but for some reason it gets <code>null<\/code> value when it&#8217;s used in subreports SQL with the <code>P!{}<\/code> syntax.<\/p>\n<p><strong>And in more detail:<\/strong><\/p>\n<p>I have two almost identical subreports. I would like to use a generic subreport instead of defining each subreport individually. Now I have this subreport that takes a string parameter <code>main_or_side<\/code>. The idea is to pass value &#8220;main&#8221; or &#8220;side&#8221; to the subreport and then use this in the SQL-query.<\/p>\n<p>In the query the parameter is used this way: <code>SELECT table.P!{main_or_side}_diagnosis ...<\/code> and should result for example <code>SELECT main_diagnosis ...<\/code> when it&#8217;s called with the parameter.<\/p>\n<p>When I preview the subreport in iReports it prompts to ask for the parameter and when I enter &#8220;main&#8221; or &#8220;side&#8221; it shows the report fine. Now when I preview the mainreport where I have set it to pass value <code>new String(\"main\")<\/code> as <code>side_or_main<\/code>-parameter, it&#8217;ll return an error:<\/p>\n<pre><code>Unknown column 'table.null_diagnosis' in 'field list'<\/code><\/pre>\n<p>If I make the query static and add a textField to show the value of <code>main_or_side<\/code> it shows the passed value fine. So the value get&#8217;s passed to the subreport for sure. How can it be that inside the SQL-query <code>P!{main_or_side}<\/code> evaluates to <code>null<\/code>?<\/p>\n<p><strong>EDIT:<\/strong><\/p>\n<p>I was doing some cleanup and renaming to copies of my jrxml-files so I could past snippets here. After I removed few irrelevant elements and did some renaming to make to code match my description it started suddenly working.<\/p>\n<p>The problem persists on the original files. I&#8217;ll try to go through the differences compared to the modified files and post here if I find out what was causing the problem.<\/p>\n<p id=\"rop\"><small>Originally posted 2014-02-08 03:35:46. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>In short: I&#8217;m passing a constant string to a subreport, but for some reason it gets null value when it&#8217;s used in subreports SQL with the P!{} syntax. And in more detail: I have two almost identical subreports. I would like to use a generic subreport instead of defining each subreport individually. Now I have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2724","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2724"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2724\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}