Replacing where clause dynamically in query
<p>In my report query I have a where clause that needs to be replaced dynamically based on the data chosen in the front end.<br><br>
The query is something like :<br>
</p>
<p><em><select statement></em></p>
<p><em>where ?=?</em></p>
<p> </p>
<p> </p>
<p>I already have a code to replace the value - I created report parameter and linked to the value ? in the query. <br><br>
Example: <br><em><select statement><br>
where name=?</em></p>
<p> </p>
<p>Any value of name that comes from front end replaces the ? in the where clause - this works fine.</p>
<p> </p>
<p> </p>
<p>But now I need to replace the entire clause. Should I create two parameters and link them to both the '?' ?<br>
Can anyone help with this?<br><br>
Thanks !</p>
The query is something like :<br>
</p>
<p><em><select statement></em></p>
<p><em>where ?=?</em></p>
<p> </p>
<p> </p>
<p>I already have a code to replace the value - I created report parameter and linked to the value ? in the query. <br><br>
Example: <br><em><select statement><br>
where name=?</em></p>
<p> </p>
<p>Any value of name that comes from front end replaces the ? in the where clause - this works fine.</p>
<p> </p>
<p> </p>
<p>But now I need to replace the entire clause. Should I create two parameters and link them to both the '?' ?<br>
Can anyone help with this?<br><br>
Thanks !</p>
0
Comments
-
<p>One option is to change your query to:</p>
<p> </p>
<p>select x from y where myplaceholder1 = 'myplaceholder2'</p>
<p> </p>
<p>Then add the parameter values in code. That is done by selecting the data set and clicking the Script tab. Go to the beforeOpen event and enter the following:</p>
<p> </p>
<p>this.queryText = this.queryText.replace("myplaceholder1", params["p1"].value).replace("myplaceholder2", params["p2"].value);</p>
<p> </p>
<p>(replace "p1" and "p2" with the names of your two parameters)</p>
Warning No formatter is installed for the format ipb0 -
<p>Hi New_Bee,</p>
<p> </p>
<p>defining a query dynamically is done with coding i.e. you can add or replace part of the query depending on many paramters.</p>
<p>for instance you can have things like</p>
<pre class="_prettyXprint _lang-">
var myWhere = " where (1=1) ";
if (params["p1"] == 'A' && params["p2"] == 'B') var myWhere = " and field1=" + params["p3"];
if (params["p1"] == 'A' && params["p2"] != 'B') var myWhere = " and field1=" + params["p4"];
if (params["p1"] != 'A' && params["p2"] == 'B') var myWhere = " and field1=" + params["p5"];
if (params["p1"] != 'A' && params["p2"] != 'B') var myWhere = " and field1=" + params["p6"];
this.queryText += myWhere; </pre>
<p><a data-ipb='nomediaparse' href='http://developer.actuate.com/community/forum/index.php?/topic/35490-dynamic-query-whole-where-clause-not-standard-field1/'>Take a look on this thread here</a></p>Warning No formatter is installed for the format ipb0
Categories
- All Categories
- 108 Developer Announcements
- 53 Articles
- 106 General Questions
- 144 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 899 Cloud Fax and Notifications
- 77 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 120 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management