<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic LETing multiple field values in a sciprt variable in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904836#M74607</link>
    <description>&lt;P&gt;Hi all!&lt;/P&gt;
&lt;P&gt;We're trying to store a list of values in a &lt;LI-PRODUCT title="Qlik Sense Business" id="qlikSenseBusiness"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp; script variable.&lt;/P&gt;
&lt;P&gt;Those values are the values of a field already loaded in script.&lt;/P&gt;
&lt;P&gt;The destiny of the variable is to be used in a "Where in" SQL SELECT query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can We do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I mean (pseudocode):&lt;/P&gt;
&lt;P&gt;TableA: LOAD FieldA, FieldB FROM wherever; //Load tableA with FieldB wich values would listed on vMyVariable&lt;/P&gt;
&lt;P&gt;LET vMyVariable = read all FieldB values; //That's the question!!&lt;/P&gt;
&lt;P&gt;TableB: SQL SELECT FieldC, FieldD FROM postgresdatabase where FieldD in ($(vMyVarialbe)); //Load TableB fields where FieldD values are equals to FieldB ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think an approach would be to populate the variable as we're reading Table A fields one by one in a FOR loop:&lt;/P&gt;
&lt;P&gt;LET vMyVariable='';&amp;nbsp; //Start the variable with no values&lt;/P&gt;
&lt;P&gt;FOR i in NoOfRows(TableA) //Looping over all TableA rows&lt;/P&gt;
&lt;P&gt;LET vMyVariable = vMyVariable &amp;amp; ',' &amp;amp; Peek(FieldB); //Insert FieldB value for i row into variable&lt;/P&gt;
&lt;P&gt;NEXT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, there'is another way to do it? a more elegant and/or economic one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Alonso Torres&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2022 15:19:58 GMT</pubDate>
    <dc:creator>Gestion-PSD</dc:creator>
    <dc:date>2022-03-14T15:19:58Z</dc:date>
    <item>
      <title>LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904836#M74607</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;
&lt;P&gt;We're trying to store a list of values in a &lt;LI-PRODUCT title="Qlik Sense Business" id="qlikSenseBusiness"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp; script variable.&lt;/P&gt;
&lt;P&gt;Those values are the values of a field already loaded in script.&lt;/P&gt;
&lt;P&gt;The destiny of the variable is to be used in a "Where in" SQL SELECT query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can We do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I mean (pseudocode):&lt;/P&gt;
&lt;P&gt;TableA: LOAD FieldA, FieldB FROM wherever; //Load tableA with FieldB wich values would listed on vMyVariable&lt;/P&gt;
&lt;P&gt;LET vMyVariable = read all FieldB values; //That's the question!!&lt;/P&gt;
&lt;P&gt;TableB: SQL SELECT FieldC, FieldD FROM postgresdatabase where FieldD in ($(vMyVarialbe)); //Load TableB fields where FieldD values are equals to FieldB ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think an approach would be to populate the variable as we're reading Table A fields one by one in a FOR loop:&lt;/P&gt;
&lt;P&gt;LET vMyVariable='';&amp;nbsp; //Start the variable with no values&lt;/P&gt;
&lt;P&gt;FOR i in NoOfRows(TableA) //Looping over all TableA rows&lt;/P&gt;
&lt;P&gt;LET vMyVariable = vMyVariable &amp;amp; ',' &amp;amp; Peek(FieldB); //Insert FieldB value for i row into variable&lt;/P&gt;
&lt;P&gt;NEXT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, there'is another way to do it? a more elegant and/or economic one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Alonso Torres&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:19:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904836#M74607</guid>
      <dc:creator>Gestion-PSD</dc:creator>
      <dc:date>2022-03-14T15:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904846#M74608</link>
      <description>&lt;P&gt;Load Concat(Field,',') as Fields INLINE [&lt;BR /&gt;Field&lt;BR /&gt;Value1&lt;BR /&gt;Value2&lt;BR /&gt;Value3&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;Let vValues = peek('Fields');&lt;/P&gt;
&lt;P&gt;Note that this will only work for numeric values insofar as WHERE IN - if you want to use it for textual values, you'll need slap a chr(39) around each value during the concat() phase to comply with e.g. IN ('Hello','World').&lt;/P&gt;
&lt;P&gt;As long as the list of values isn't particularly long, and I'm guessing it isn't, you could also use the loop approach as well without any serious impact to performance.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:29:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904846#M74608</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2022-03-14T15:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904847#M74609</link>
      <description>&lt;P&gt;Hi again!&lt;/P&gt;
&lt;P&gt;Sorry for my quick repost, but I think I've found exactly what we're looking for:&lt;/P&gt;
&lt;P&gt;FOR EACH i in &lt;STRONG&gt;FIELDVALUELIST&lt;/STRONG&gt;('FieldB')&lt;BR /&gt;&amp;nbsp; LET vMyVariable= '$(vMyVariable)' &amp;amp; ',' &amp;amp; i;&lt;BR /&gt;NEXT;&lt;/P&gt;
&lt;P&gt;And later, to erase first comma in the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need to test it, but it's promising.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Alonso Torres.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:30:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904847#M74609</guid>
      <dc:creator>Gestion-PSD</dc:creator>
      <dc:date>2022-03-14T15:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904854#M74610</link>
      <description>&lt;P&gt;Thaks Or for your quick reply.&lt;/P&gt;
&lt;P&gt;We're going to test your approach, too.&lt;/P&gt;
&lt;P&gt;We're talking about less to 200 rows in TableA. In fact. FieldB is numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, as I understand, you said:&lt;/P&gt;
&lt;P&gt;TableA: LOAD FieldA, FieldB FROM wherever; //Load tableA with FieldB wich values would listed on vMyVariable.&lt;/P&gt;
&lt;P&gt;STORE TableA; //We need this table in other context&lt;/P&gt;
&lt;P&gt;IntermediateTable:&lt;/P&gt;
&lt;P&gt;LOAD Concat(FieldB,',') AS FieldB_to_variable;&lt;/P&gt;
&lt;P&gt;LET vMyVariable = PEEK(FieldB_to_variable);&lt;/P&gt;
&lt;P&gt;DROP TABLES TableA,IntermediateTable;&lt;/P&gt;
&lt;P&gt;TableB: SQL SELECT FieldC, FieldD FROM postgresdatabase where FieldD in ($(vMyVarialbe)); //Load TableB fields where FieldD values are equals to FieldB ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems interesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:40:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904854#M74610</guid>
      <dc:creator>Gestion-PSD</dc:creator>
      <dc:date>2022-03-14T15:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904859#M74611</link>
      <description>&lt;P&gt;Hi again.&lt;/P&gt;
&lt;P&gt;As far as we've tested, your solution is much better than ours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 15:54:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904859#M74611</guid>
      <dc:creator>Gestion-PSD</dc:creator>
      <dc:date>2022-03-14T15:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904934#M74614</link>
      <description>&lt;P&gt;Yup, you can loop through fieldvaluelist() as well. As I said, with only 200 values, I wouldn't expect it to take a long time using any method. Also note that if the values are textual, you will still need to get the quotes in unless they're already part of the text string, using chr(39) &amp;amp; '$(vMyVariable)' &amp;amp; chr(39), I think.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 18:46:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/1904934#M74614</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2022-03-14T18:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: LETing multiple field values in a sciprt variable</title>
      <link>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/2079563#M88563</link>
      <description>&lt;P&gt;Using a combination of the above answers, here's what I came up with. This is assuming that the field you want string-a-fied is called FieldB, FieldB is a text value, and it's stored in table TableA:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;LOAD&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000FF"&gt;CONCAT&lt;/FONT&gt;(FieldB, chr(39) &amp;amp; ',' &amp;amp; chr(39)) as FieldBString&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000FF"&gt;RESIDENT&lt;/FONT&gt; TableA;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT color="#0000FF"&gt;LET&lt;/FONT&gt; myV2 = chr(39) &amp;amp; FieldValue('FieldBString',1) &amp;amp; chr(39);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And at the end of the SQL Load:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;WHERE FieldB IN ($(myV2));&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also - this will only work with &amp;lt;1000 values.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 20:03:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LETing-multiple-field-values-in-a-sciprt-variable/m-p/2079563#M88563</guid>
      <dc:creator>amandalyst</dc:creator>
      <dc:date>2023-06-02T20:03:27Z</dc:date>
    </item>
  </channel>
</rss>

