Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Create a birt report with if/else condition.
gaganthapar
<p>I need to run a query in the database. If the output (list of numbers) of the query (1) is one of these numbers -100,400,500, I need to run one more query (2), and if the output is either 200 or 300, I need to run a different query (3). </p>
<p> </p>
<p>The report will display the output of either (2) or (3) because they both have same columns, but different results based on the input.</p>
<p> </p>
<p>All queries are from same dataset. The user inputs will be put in query (2) or (3).</p>
<p> </p>
<p>Can someone help me in achieving it?</p>
Find more posts tagged with
Comments
PaulCooper
<p>gaganthapar,</p>
<p> </p>
<p>Assuming you mean that Query (1) returns only one column and one row (i.e. one number) then you do:</p>
<pre class="_prettyXprint">
select ... /*Query 2*/
from ...
where ...
and (select /*Query 1*/ ...) in (-100, 400, 500)
union all
select ... /*Query 3*/
from ...
where ...
and (select /*Query 1*/ ...) in (200, 300)</pre>
<p>Make sure Query 2 has all the column aliases you require.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>Paul</p>
gaganthapar
<p>Query 1 can return multiple rows but one column. And then based on the output, I will run either query 2 or query 3.</p>
PaulCooper
<p>So what do you want it to do if it returns two rows with -100 and 200?</p>
gaganthapar
<blockquote class="ipsBlockquote" data-author="PaulCooper" data-cid="139217" data-time="1443033336">
<div>
<p>So what do you want it to do if it returns two rows with -100 and 200?</p>
</div>
</blockquote>
<p>Thank you. Then for 100, I will run query 2 and for 200, I will run query 3.</p>
PaulCooper
<p>So the number from Query 1 is a parameter in Queries 2 and 3?</p>
<p>Also if query 1 returns 4 numbers it runs four queries, some 2 and some 3?</p>
gaganthapar
<blockquote class="ipsBlockquote" data-author="PaulCooper" data-cid="139219" data-time="1443033712">
<div>
<p>So the number from Query 1 is a parameter in Queries 2 and 3?</p>
</div>
</blockquote>
<p> </p>
<p>Sorry. This is what I want to do
.</p>
<p> </p>
<p>Select distinct wbs_num from item_table.</p>
<p> </p>
<p>wbs_num can be list of values. If the wbs_num is 100 or 400 or 500. I have to run the query 2. </p>
<p> </p>
<p>if wbs_num is 200 or 300, I will run query 3.</p>
<p> </p>
<p>WBS_NUM is not a parameter in query 2 or 3.</p>
<p> </p>
<p>Can I write the query 1 in "beforeOpen" script and based on the output, I will run query 2 or 3?</p>
PaulCooper
<p>Ok this sounds like what you need:</p>
<pre class="_prettyXprint">
select ... /*Query 2*/
from ...
where ...
and exists (select wbs_num from item_table where wbs_num in (100, 400, 500))
union all
select ... /*Query 3*/
from ...
where ...
and exists (select wbs_num from item_table where wbs_num in (200, 300))</pre>
<p>There is no need to put distinct in query 1 in the EXISTS clause.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>Paul</p>
gaganthapar
<blockquote class="ipsBlockquote" data-author="PaulCooper" data-cid="139221" data-time="1443034779">
<div>
<p>Ok this sounds like what you need:</p>
<pre class="_prettyXprint">
select ... /*Query 2*/
from ...
where ...
and exists (select wbs_num from item_table where wbs_num in (100, 400, 500))
union all
select ... /*Query 3*/
from ...
where ...
and exists (select wbs_num from item_table where wbs_num in (200, 300))</pre>
<p>There is no need to put distinct in query 1 in the EXISTS clause.</p>
<p> </p>
<p>Regards,</p>
<p> </p>
<p>Paul</p>
</div>
</blockquote>
<p>I think it should solve the problem. Thank you
</p>