Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
MODIFYING THE QUERY DYNAMICALLY
arunkumarb
Hi,<br />
<br />
I have a query as shon below. I placed this query in dataset. Now If i pass the parameters like JAN,FEB,MAR....I would like to replace 'APR' with my parameter value like JAN, FEB....<br />
<br />
select <br />
sum(<span style='color: #FF0000'>APR</span>_OPBAL) AS AA, <br />
sum(<span style='color: #FF0000'>APR</span>_OPBAL_VAL_PTR), <br />
sum(<span style='color: #FF0000'>APR</span>_OPBAL_VAL_BPTR), <br />
sum(<span style='color: #FF0000'>APR</span>_PURCHASE_QTY), <br />
sum(<span style='color: #FF0000'>APR</span>_PURCHASE_VAL_PTR), <br />
sum(<span style='color: #FF0000'>APR</span>_PURCHASE_VAL_BPTR), <br />
sum(<span style='color: #FF0000'>APR</span>_SOLD_QTY), <br />
sum(<span style='color: #FF0000'>APR</span>_SOLD_VAL_PTR), <br />
sum(<span style='color: #FF0000'>APR</span>_SOLD_VAL_BPTR), <br />
sum(<span style='color: #FF0000'>APR</span>_ADJUST_QTY), <br />
sum(<span style='color: #FF0000'>APR</span>_ADJUST_VAL_PTR), <br />
sum(<span style='color: #FF0000'>APR</span>_ADJUST_VAL_BPTR),<br />
sum( <span style='color: #FF0000'>APR</span>_HMSRET_QTY), <br />
sum(<span style='color: #FF0000'>APR</span>_HMSRET_VAL_PTR), <br />
sum(<span style='color: #FF0000'>APR</span>_HMSRET_VAL_BPTR),<br />
sum( <span style='color: #FF0000'>APR</span>_CLBAL), <br />
sum(<span style='color: #FF0000'>APR</span>_CLBAL_VAL_PTR),<br />
sum( <span style='color: #FF0000'>APR</span>_CLBAL_VAL_BPTR) <br />
from tbl_summary_rate where year=2010<br />
<br />
<br />
plz help me.<br />
<br />
Thanks and Regards,<br />
Arun
Find more posts tagged with
Comments
Clement Wong
Arun,<br />
<br />
Assuming your original query in the Data Set is "APR", you can overwrite the <em class='bbc'>beforeOpen </em>method of the Data Set and use Java String method, <em class='bbc'>replaceAll</em>, to replace the original text with the selected parameter value.<br />
<br />
Example:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.queryText = this.queryText.replaceAll("APR", params["yourMonthParm"]);</pre>
<br />
Note to be safe, that in your original query text, you may want to use an obscure dummy text name for that month in the original text such as XXXXXXX so that you won't clobber any other values that may have "APR". Or instead of searching for "APR", you search for "sum(APR_" and you replace it with "sum(" plus the parameter month plus "_".