<?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 Re: Query based on variable input in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347235#M114512</link>
    <description>&lt;P&gt;Thank you very much for this, it has worked.&lt;/P&gt;&lt;P&gt;Even though on the test run query within the query window it spat out an error it works when actually running.&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 13:32:03 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-02-08T13:32:03Z</dc:date>
    <item>
      <title>Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347229#M114506</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I need to run a query multiple times (loop) against a database.&lt;/P&gt; 
&lt;P&gt;The query has one variable called HOLDER and in the example below it is set to 0000.&lt;/P&gt; 
&lt;P&gt;The variables are stored on a different csvinputfile, (one column, and one per line around 40,000).&lt;/P&gt; 
&lt;P&gt;So the query will need to run around 40,000 times base don the line count.&lt;/P&gt; 
&lt;P&gt;I need the output data in One CSV file. It must add another column called QueriedVariable and within this column there needs to be the variable from HOLDER which was used in the query for the results (every row of the result must contain the HOLDER variable which was used to generate the results).&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I would be greatful for any help provided.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;SELECT ISET.ENTRY.TRANS_ID, ISET.ENTRY.ACCOUNT_ID, ISET.ENTRY.SECURITY_ID,
  ((ISET.ENTRY.AMOUNT * -1)/100) AS Amount, ISET.ENTRY.VAL_DATE, ISET.ENTRY.NARRATIVE,
  ISET.ENTRY.RECONCILED, ISET.ENTRY.TICK_COLOUR, ISET.ENTRY.\"REF\",ISET.TRANS.TRANS_ID,
  ISET.TRANS.PHYSICAL_DATE, ISET.TRANS.STATEMENT_DATE, ISET.TRANS.PROCESS, ISET.TRANS.LOGGED_USER,
  ISET.TRANS.\"TYPE\", ISET.TRANS.HOLDER, ISET.TRANS.TRANS_NARRATIVE, ISET.ACCOUNT.HOLDER,
  (ABS(ISET.ENTRY.AMOUNT)/100) AS Amount2
FROM ISET.ENTRY
INNER JOIN ISET.TRANS ON  ISET.ENTRY.TRANS_ID= ISET.TRANS.TRANS_ID
INNER JOIN ISET.ACCOUNT ON ISET.ENTRY.ACCOUNT_ID = ISET.ACCOUNT.ACCOUNT_ID
WHERE ISET.ENTRY.ACCOUNT_ID IN (SELECT ACCOUNT_ID FROM ACCOUNT START WITH HOLDER = '0000' CONNECT BY NOCYCLE PRIOR ACCOUNT_ID = PARENT);&lt;/PRE&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 16:45:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347229#M114506</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-07T16:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347230#M114507</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Use the following pattern:&lt;/P&gt;&lt;PRE&gt;tFileInputDelimited--&amp;gt;tFlowToIterate--&amp;gt;tMySQLInput--&amp;gt;tFileOutputDelimited&lt;/PRE&gt;&lt;P&gt;- tFileInputDelimited to read your input file&lt;/P&gt;&lt;P&gt;- tFlowToIterate to generate a set of global variables (1 per field for the current record - see documentation for details)&lt;/P&gt;&lt;P&gt;- tMySQLInput (replace by your DB connector) to query your&amp;nbsp;database + arrange the schema as expected for your select&lt;/P&gt;&lt;P&gt;&amp;nbsp; in the query field, replace the HOLDER value in the query by the corresponding global variable and add the new pseudo-column here called MyHolder&lt;/P&gt;&lt;P&gt;&amp;nbsp; assuming the global is called "HOLDER" you can do it like this:&lt;/P&gt;&lt;PRE&gt;"select '" + (String)globalMap.get("HOLDER") + "' AS MyHolder, ISET.ENTRY.TRANS_ID, ISET.ENTRY.ACCOUNT_ID, blablabla &lt;BR /&gt; from blablabla &lt;BR /&gt; where blablabla&amp;nbsp;&lt;BR /&gt; START WITH HOLDER = '" + (String)globalMap.get("HOLDER") + "' CONNECT BY..."&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;-tFilleOutputDelimited to get the result (tick the Appen option)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this is enough to let&amp;nbsp;go with the solution.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 17:54:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347230#M114507</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2018-02-07T17:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347231#M114508</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks for the reply.&lt;/P&gt; 
&lt;P&gt;This doesnt seem to work, i am trying with a simpler query:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Original Query brings results :&lt;/P&gt; 
&lt;PRE&gt;SELECT TRANS_ID, ACCOUNT_ID, BANK_ACCOUNT_ID, SECURITY_ID, AMOUNT, VAL_DATE, NARRATIVE
FROM ISET.CASH_ENTRY
WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER = '12345')&lt;/PRE&gt; 
&lt;P&gt;Query based on your suggestion:&lt;/P&gt; 
&lt;PRE&gt;select&amp;nbsp; TRANS_ID, ACCOUNT_ID, BANK_ACCOUNT_ID, SECURITY_ID, AMOUNT, VAL_DATE, NARRATIVE&lt;BR /&gt;FROM ISET.CASH_ENTRY&lt;BR /&gt;WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID&lt;BR /&gt;FROM ISET.ACCOUNT&lt;BR /&gt;WHERE HOLDER ='" + (String)globalMap.get("HOLDER") + "' )&lt;/PRE&gt; 
&lt;P&gt;Also there seems to be a difference in how the query is presented in the component screen :&lt;/P&gt; 
&lt;PRE&gt;"select  TRANS_ID, ACCOUNT_ID, BANK_ACCOUNT_ID, SECURITY_ID, AMOUNT, VAL_DATE, NARRATIVE
FROM ISET.CASH_ENTRY
WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER ='\" + (String)globalMap.get(\"HOLDER\") + \"' )"&lt;/PRE&gt; 
&lt;P&gt;I am only using a simple input file with three rows (which when manually tested bring up results),&lt;/P&gt; 
&lt;PRE&gt;CLIENT
1234
4321
1551&lt;/PRE&gt; 
&lt;P&gt;In the tFlowToIterate i have unticked the "Use the Default (Key.......)" and customised so the key is "HOLDER" and value is set to "CLIENT" which is the only field/column in the input file.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Any further help would be greatly appreciated.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:08:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347231#M114508</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T11:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347232#M114509</link>
      <description>&lt;P&gt;do you have an error or just no result?&lt;/P&gt;
&lt;P&gt;if you have an error try with the following for the query:&lt;/P&gt;
&lt;PRE&gt;"select  TRANS_ID, ACCOUNT_ID, BANK_ACCOUNT_ID, SECURITY_ID, AMOUNT, VAL_DATE, NARRATIVE
FROM ISET.CASH_ENTRY
WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER ='" + (String)globalMap.get("HOLDER") + "')"&lt;/PRE&gt;
&lt;P&gt;if you have no result, share your&amp;nbsp;&lt;SPAN&gt;tFlowToIterate&amp;nbsp;settings with the corresponding schema&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:19:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347232#M114509</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2018-02-08T11:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347233#M114510</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt; 
&lt;P&gt;That seems to work with the small query, but if I try and edit the larger one it doesn't work:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;SELECT ISET.ENTRY.TRANS_ID, ISET.ENTRY.ACCOUNT_ID, ISET.ENTRY.SECURITY_ID,
((ISET.ENTRY.AMOUNT * -1)/100) AS Amount, ISET.ENTRY.VAL_DATE, ISET.ENTRY.NARRATIVE,
ISET.ENTRY.RECONCILED, ISET.ENTRY.TICK_COLOUR, ISET.ENTRY."REF",ISET.TRANS.TRANS_ID,
ISET.TRANS.PHYSICAL_DATE, ISET.TRANS.STATEMENT_DATE, ISET.TRANS.PROCESS, ISET.TRANS.LOGGED_USER,
ISET.TRANS."TYPE", ISET.TRANS.HOLDER, ISET.TRANS.TRANS_NARRATIVE, ISET.ACCOUNT.HOLDER,
(ABS(ISET.ENTRY.AMOUNT)/100) AS Amount2
FROM ISET.ENTRY
INNER JOIN ISET.TRANS ON  ISET.ENTRY.TRANS_ID= ISET.TRANS.TRANS_ID
INNER JOIN ISET.ACCOUNT ON ISET.ENTRY.ACCOUNT_ID = ISET.ACCOUNT.ACCOUNT_ID
WHERE ISET.ENTRY.ACCOUNT_ID IN (SELECT ACCOUNT_ID FROM ACCOUNT START WITH HOLDER = '" + (String)globalMap.get("HOLDER") + "' CONNECT BY NOCYCLE PRIOR ACCOUNT_ID = PARENT)&lt;/PRE&gt; 
&lt;P&gt;Also if I enclose this in double quotes then i get an error&amp;nbsp; - ORA-00972 identifier is too long.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Do you have skype by any chance?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:46:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347233#M114510</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T11:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347234#M114511</link>
      <description>&lt;P&gt;The rule you MUST respect is that the query is a string so you MUST enclose it between "".&lt;/P&gt;
&lt;P&gt;So, add " at the beginning and at the end.&lt;/P&gt;
&lt;P&gt;Then remove "" around REF and TYPE fields.&lt;/P&gt;
&lt;P&gt;If it doesn't work try \"REF\" and \"TYPE\".&lt;/P&gt;
&lt;P&gt;If it doesn't work anymore try the query under SQL*Plus (replace the global by its value for this test).&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:58:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347234#M114511</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2018-02-08T11:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Query based on variable input</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347235#M114512</link>
      <description>&lt;P&gt;Thank you very much for this, it has worked.&lt;/P&gt;&lt;P&gt;Even though on the test run query within the query window it spat out an error it works when actually running.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 13:32:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Query-based-on-variable-input/m-p/2347235#M114512</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T13:32:03Z</dc:date>
    </item>
  </channel>
</rss>

