Home
Analytics
Trying to parse multi select list to (SQL in) clause
JagannathaSuta
<p>I have tried looking through this form to find the answer, todate I have not had any luck finding anything that suits my needs, or I have not adequatly described my situation in the search option, apologies for that.</p>
<p> </p>
<p>I am trying to get multiple items into my IN cluase in the where statement, I am using Eclipse Version: 3.7.1.</p>
<p> </p>
<p>This is in the script -> open section.</p>
<p> </p>
<p>var where = "";<br>
if (params["CREWID"].value)<br>
where = " W.CREWID IN ('" + params["CREWID"].value + "')";</p>
<p> </p>
<p>The values I am getting from Maximo look like this =CREW1,=CREW2, I would really like to be able to format the output to be ('CREW1','CREW2'). If I manually change the list output in Maximo to be CREW1','CREW2 it works. I omit the first and last single quotes as they are already included in the where = " W.CREWID IN ('" + params["CREWID"].value + "')"; statement.</p>
<p> </p>
<p>Thanks in advance</p>
<p>Jag</p>
Find more posts tagged with
Comments
wwilliams
<p>try using MXReportSqlFormat.createParamWhereClause("w.crewid", params["CREWID"])</p>
JagannathaSuta
<p>Thanks for the reply wwilliams, but there is no context around how or where to use this.</p>
<p> </p>
<p>I am not sure that this would resolve my situation.</p>
<p> </p>
<p>I need the values that are uiput into CREWID to be formatted from =CREWID1, =CREWID2 to CREWID1','CREWID2</p>
<p> </p>
<p>the values are picked up from the Maximo list box, as there is no indication that the function you have so kindly offered me, does not look like it is formatting the string to the format that is usable in the query.</p>
wwilliams
<p><a data-ipb='nomediaparse' href='
http://www-01.ibm.com/support/docview.wss?uid=swg21605970'>http://www-01.ibm.com/support/docview.wss?uid=swg21605970</a></p>
;
JagannathaSuta
<p>Hhhmmm, not sure ow that applies to what I have set up.</p>
<p> </p>
<p>the query I have built is looking for the values in the in clause to be in('CREWID1','CREWID2')</p>
<p>I do not relish the idea of declaring all 100+ CREWID's in the open script section.</p>
<p> </p>
<p>Is there no way to parse the current in(=CREWID1,=CREWID2) in to "in('CREWID1','CREWID2)<br><br>
As the document you pointed me to indicates the way to deal with multiselect parameters is to declare them, this I am not to keen on as there may be anywhere from 1 - 100+ CREWID's selected at run time.</p>
wwilliams
<p> MXReportSqlFormat.createParamWhereClause("person.displayname", params["user"]);</p>
<p> </p>
<p>equates to</p>
<p> </p>
<p>((person.displayname = 'ZZ1234') or (person.displayname = 'ZZWILSON'))</p>
<p> </p>
<p>If I entered in the parameter =ZZ1234,=ZZWILSON</p>
wwilliams
<p>this isn't pretty, but it appears to work</p>
<pre class="_prettyXprint _lang-js">
myWhere = new String();
var temp = new Array()
var myString = params["crew"] ;
temp =myString.split(",");
for (var i=0;i< myString.split(",").length; i++ ) {
myWhere = myWhere + "'" + temp[i] +"',";
}
myWhere = myWhere.replace(/,\s*$/,"");
myWhere = " w.crewid in ("+ myWhere + ")"
</pre>
<p>Parameter Fred,Tom,Lou</p>
<p>Fri Jun 23 13:58:16 CDT 2017 DEBUG >>> myWhere: w.crewid in ('Fred','Tom','Lou')</p>
JagannathaSuta
<p>Nearly there, awesome piece of code.</p>
<p> </p>
<p>Result from your code:</p>
<p> </p>
<p>AND w.crewid in ('=APS','=APSCARP')</p>
<p> </p>
<p>How can we no remove the =</p>
<p> </p>
<p>Thanks for your persistence and patience :-)</p>
wwilliams
<p>var myString = params["crew"].replace(/=/g,'') ;</p>
<p> </p>
<p>by the way</p>
<p>Parameter =Fred,=Tom,=Lou</p>
<p>scriptLogger.debug(" MxWhere " + MXReportSqlFormat.createParamWhereClause("w.crewid", params["crew"]))</p>
<p> </p>
<p>results in</p>
<p>MxWhere ((w.crewid = 'Fred') or (w.crewid = 'Tom') or (w.crewid = 'Lou'))</p>
<p> </p>
<p>so tell me again why it wouldn't work for you</p>
JagannathaSuta
<p>Hi wwilliams,<br>
With the fisrt bit of code you kindly provided, it was able to format the Maximo parameter string from =CREWID1,=CREWID2 to be</p>
<p>Where crewid in ('=CREWID1','=CREWID2')</p>
<p>But I have the code set up to use the "IN" statement, using where ((w.crewid = 'CREW1') or (w.crew = 'CREWID2')) may not work as there may be dozens of selections made.</p>
<p> </p>
<p>However I have managed to resolve the issue with thanks to you for supplying me with the code.</p>
<p> </p>
<p>With a little bit of tweaking I have manage to get the results I was after.</p>
<p> </p>
<p>var myWhere = new String();<br>
var temp = new Array()<br>
var myString = params["CREWID"] ;<br>
temp = myString.split(",");<br><br>
for (var i=0;i< myString.split(",").length; i++ )<br>
{<br>
myWhere = myWhere + "'" + temp
+"',";<br>
}<br>
myWhere = myWhere.replace(/=/g,"");<br>
myWhere = myWhere.replace(/,\s*$/,"");<br>
myWhere = " w.crewid in ("+ myWhere + ")"</p>
<p> </p>
<p>This acheives what I need.</p>
<p> </p>
<p>Thank you.</p>