<?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: Translating a complex SQL query into a tDBInput in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335536#M104085</link>
    <description>&lt;P&gt;OK, you need to set your table that is being used as your lookup to "reload at each row" in your tMap. Then join from your main source to that lookup using the globalMap key field that you should see appear when you set "reload at each row". What this does is take every row from your main source and pass whatever values you choose, from that row to a globalMap value. You can then use those globalMap values in your query for your lookup table. The lookup table will fire for every main row that is returned. So the process of assigning globalMap values and dynamically setting your SQL will be carried out for every row. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a mini tutorial I put together for a similar scenario. It shows everything you will need to do, apart from modifying your SQL. In this case, instead of using the values for SQL, I am using them for generating rows with a tJavaFlex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;https://community.talend.com/s/question/0D53p00007vCpvECAS/row-multiplication&lt;/P&gt;</description>
    <pubDate>Wed, 30 Nov 2022 14:05:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-11-30T14:05:17Z</dc:date>
    <item>
      <title>Translating a complex SQL query into a tDBInput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335533#M104082</link>
      <description>&lt;P&gt;Hello I have a rather long and complex SQL query and I am finding difficulties in changing its formatting so that it is "accepted" in a tDBInput.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Here is the query :&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select distinct a.ID_FAM, a.ID_AY, a.ID_ORG, fp.ID_PROD&amp;nbsp;&lt;/P&gt;&lt;P&gt;into :idFam%, :idAy%, :idOrg1%, :IdProd$&lt;/P&gt;&lt;P&gt;from AY a, FPROD fp, PROD P, ORG O, DCSE D&lt;/P&gt;&lt;P&gt;where &lt;B&gt;&lt;I&gt;a.AY_SS&lt;/I&gt;&lt;/B&gt; = '&lt;B&gt;TALEND_VAR1&lt;/B&gt;'&lt;/P&gt;&lt;P&gt;and a.ID_FAM = fp.ID_FAM&lt;/P&gt;&lt;P&gt;and fp.ID_ORG = a.ID_ORG&lt;/P&gt;&lt;P&gt;and fp.ID_ORG = P.ID_ORG&lt;/P&gt;&lt;P&gt;and fp.ID_PROD = P.ID_PROD&lt;/P&gt;&lt;P&gt;and fp.ID_ORG = O.ID_ORG&lt;/P&gt;&lt;P&gt;and D.DCSE_NOM = 'NOEMIE'&lt;/P&gt;&lt;P&gt;and ((('NOEMIE' &amp;lt;&amp;gt; 'NOEMIE' and D.DCSE_PP = 0) and fp.ID_PROD = 'SANTE') or (('NOEMIE' = 'NOEMIE' or D.DCSE_PP = 1) and (fp.ID_PROD = O.ORG_PROD or P.PROD_PRESTATION_SANTE = 1)))&lt;/P&gt;&lt;P&gt;and fp.ID_FAM = a.ID_FAM&lt;/P&gt;&lt;P&gt;and ((&lt;B&gt;&lt;I&gt;a.AY_DATNAIS&lt;/I&gt;&lt;/B&gt; =&amp;nbsp;decode('&lt;B&gt;TALEND_VAR2&lt;/B&gt;', 1, to_date('&lt;B&gt;TALEND_VAR2&lt;/B&gt;', 'dd/mm/yyyy'), &lt;B&gt;&lt;I&gt;a.AY_DATNAIS&lt;/I&gt;&lt;/B&gt;)) or (&lt;B&gt;&lt;I&gt;a.AY_DATNAIS2&lt;/I&gt;&lt;/B&gt; = '&lt;B&gt;TALEND_VAR2&lt;/B&gt;'))&lt;/P&gt;&lt;P&gt;and&lt;I&gt; &lt;/I&gt;&lt;B&gt;&lt;I&gt;a.AY_RNG&lt;/I&gt;&lt;/B&gt; = &lt;B&gt;TALEND_VAR3&lt;/B&gt;&lt;/P&gt;&lt;P&gt;and exists (select 'a' from ADC ad&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where ad.ID_AY = a.ID_AY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and ad.ID_PROD = fp.ID_PROD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and nvl(ad.id_fprod, fp.id_fprod) = fp.id_fprod&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and to_date(&lt;B&gt;TALEND_VAR4&lt;/B&gt;', 'DD/MM/RR') between ad.ADC_DATDEB and nvl( ad.ADC_DATRAD, sysdate+1))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and to_date('&lt;B&gt;TALEND_VAR4&lt;/B&gt;', 'DD/MM/RR') between&amp;nbsp;fp.FP_DATADH and nvl( fp.FP_DATRAD, sysdate+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Here is my start :&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select distinct a.ID_FAM, a.ID_AY, a.ID_ORG, fp.ID_PROD, &lt;B&gt;&lt;I&gt;a.AY_SS&lt;/I&gt;&lt;/B&gt;&lt;I&gt;, &lt;/I&gt;&lt;B&gt;&lt;I&gt;a.AY_DATNAIS&lt;/I&gt;&lt;/B&gt;, &lt;B&gt;&lt;I&gt;a.AY_DATNAIS2&lt;/I&gt;&lt;/B&gt;, &lt;B&gt;&lt;I&gt;a.AY_RNG &lt;/I&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;from AY a, FPROD fp, PROD P, ORG O, DCSE D&lt;/P&gt;&lt;P&gt;where a.ID_FAM = fp.ID_FAM&lt;/P&gt;&lt;P&gt;and fp.ID_ORG = a.ID_ORG&lt;/P&gt;&lt;P&gt;and fp.ID_ORG = P.ID_ORG&lt;/P&gt;&lt;P&gt;and fp.ID_PROD = P.ID_PROD&lt;/P&gt;&lt;P&gt;and fp.ID_ORG = O.ID_ORG&lt;/P&gt;&lt;P&gt;and D.DCSE_NOM = 'NOEMIE'&lt;/P&gt;&lt;P&gt;and ((('NOEMIE' &amp;lt;&amp;gt; 'NOEMIE' and D.DCSE_PP = 0) and fp.ID_PROD = 'SANTE') or (('NOEMIE' = 'NOEMIE' or D.DCSE_PP = 1) and (fp.ID_PROD = O.ORG_PROD or P.PROD_PRESTATION_SANTE = 1)))&lt;/P&gt;&lt;P&gt;and fp.ID_FAM = a.ID_FAM&lt;/P&gt;&lt;P&gt;and exists (select 'a',&amp;nbsp;from ADC ad&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where ad.ID_AY = a.ID_AY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and ad.ID_PROD = fp.ID_PROD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and nvl(ad.id_fprod, fp.id_fprod) = fp.id_fprod&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and to_date('&lt;B&gt;TALEND_VAR4&lt;/B&gt;', 'DD/MM/RR') between ad.ADC_DATDEB and nvl( ad.ADC_DATRAD, sysdate+1))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and to_date('&lt;B&gt;TALEND_VAR4&lt;/B&gt;', 'DD/MM/RR') between&amp;nbsp;fp.FP_DATADH and nvl( fp.FP_DATRAD, sysdate+1)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In bold, these are the values coming from my tMap. But I don't know how to do this with TALEND_VAR4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2024 22:18:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335533#M104082</guid>
      <dc:creator>stephbzr</dc:creator>
      <dc:date>2024-11-15T22:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a complex SQL query into a tDBInput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335534#M104083</link>
      <description>&lt;P&gt;I am not sure why you are supplying values for your SELECT columns (&lt;B&gt;&lt;I&gt;a.AY_SS&lt;/I&gt;&lt;/B&gt;&lt;I&gt;,&amp;nbsp;&lt;/I&gt;&lt;B&gt;&lt;I&gt;a.AY_DATNAIS&lt;/I&gt;&lt;/B&gt;,&amp;nbsp;&lt;B&gt;&lt;I&gt;a.AY_DATNAIS2&lt;/I&gt;&lt;/B&gt;,&amp;nbsp;&lt;B&gt;&lt;I&gt;a.AY_RNG&lt;/I&gt;&lt;/B&gt;) from your tMap, as these are already in your tMap. Maybe I have misunderstood the formatting here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when it comes to your TALEND_VAR4 value in your WHERE clause, this is very simple once you have seen how it works. SQL queries in Talend components are essentially just String values. As such, you can set them up dynamically. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, if I have the following query.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Select col1, col2, col3&lt;/P&gt;&lt;P&gt;From myTable&lt;/P&gt;&lt;P&gt;Where myTable.col4 = 'Hello'"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...and I want to make the value for col4 dynamic, I can do this.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Select col1, col2, col3&lt;/P&gt;&lt;P&gt;From myTable&lt;/P&gt;&lt;P&gt;Where myTable.col4 = '"+((String)globalMap.get("TALEND_VAR4"))+"'"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, my assumption here is that you are passing your TALEND_VAR4 variable to the globalMap and that it is a String.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 11:14:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335534#M104083</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-30T11:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a complex SQL query into a tDBInput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335535#M104084</link>
      <description>&lt;P&gt;Hello @Richard Hall​,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I usually put the values I am looking for in my query after the select. These are then in my schema, then I link to the values in the tMap. Here is an example : &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;The original query :&amp;nbsp;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select mr.ID_RISQ&amp;nbsp;&lt;/P&gt;&lt;P&gt;into id_risq&lt;/P&gt;&lt;P&gt;from MTDMT_RISQ mr, MCO mc&lt;/P&gt;&lt;P&gt;where mr.ID_ORG = &lt;B&gt;TALEND_VAR1&lt;/B&gt;&lt;/P&gt;&lt;P&gt;and mr.ID_PROD = &lt;B&gt;TALEND_VAR2&lt;/B&gt;&lt;/P&gt;&lt;P&gt;and mc.ID_MCO = mr.ID_MCO&lt;/P&gt;&lt;P&gt;and mc.MCO_CODE = &lt;B&gt;TALEND_VAR3&lt;/B&gt;&lt;/P&gt;&lt;P&gt;and mr.ID_ACT = &lt;B&gt;TALEND_VAR4 &lt;/B&gt;&lt;/P&gt;&lt;P&gt;and mr.MTDMT_RISQ_PRESENCE_DENT = &lt;B&gt;TALEND_VAR5&lt;/B&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With values this gives :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000aDFblAAG.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/142868iF8E9353718E24BF3/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000aDFblAAG.png" alt="0695b00000aDFblAAG.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How I translate this into Talend&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000aDFctAAG.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/153403iE485B6775FB6A4AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000aDFctAAG.png" alt="0695b00000aDFctAAG.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000aDFdDAAW.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/135286iACDB1EBEF81C83C8/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000aDFdDAAW.png" alt="0695b00000aDFdDAAW.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="0695b00000aDFZQAA4.png"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/156977i67B72701B3DAE98C/image-size/large?v=v2&amp;amp;px=999" role="button" title="0695b00000aDFZQAA4.png" alt="0695b00000aDFZQAA4.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I get the result I want.&lt;/P&gt;&lt;P&gt;This is just an example of how I usually do it and I would like to do the same for the "complex" query above. But I must admit that TALEND_VAR4 which is before BETWEEN, I wonder if it is possible to do this and how.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So concerning the dynamic value, I can't do the same as you, to put a global variable because I don't have only one value, but several. Well, I think so, but I have less experience with that. The values come from a file with several columns containing several thousand lines. I don't know if I can explain it well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 13:37:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335535#M104084</guid>
      <dc:creator>stephbzr</dc:creator>
      <dc:date>2022-11-30T13:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a complex SQL query into a tDBInput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335536#M104085</link>
      <description>&lt;P&gt;OK, you need to set your table that is being used as your lookup to "reload at each row" in your tMap. Then join from your main source to that lookup using the globalMap key field that you should see appear when you set "reload at each row". What this does is take every row from your main source and pass whatever values you choose, from that row to a globalMap value. You can then use those globalMap values in your query for your lookup table. The lookup table will fire for every main row that is returned. So the process of assigning globalMap values and dynamically setting your SQL will be carried out for every row. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a mini tutorial I put together for a similar scenario. It shows everything you will need to do, apart from modifying your SQL. In this case, instead of using the values for SQL, I am using them for generating rows with a tJavaFlex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;https://community.talend.com/s/question/0D53p00007vCpvECAS/row-multiplication&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 14:05:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335536#M104085</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-30T14:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Translating a complex SQL query into a tDBInput</title>
      <link>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335537#M104086</link>
      <description>&lt;P&gt;Thank you @Richard Hall​&amp;nbsp; for the explanation, I will take the time to look at your tutorial before making a return.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 14:11:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/Translating-a-complex-SQL-query-into-a-tDBInput/m-p/2335537#M104086</guid>
      <dc:creator>stephbzr</dc:creator>
      <dc:date>2022-11-30T14:11:19Z</dc:date>
    </item>
  </channel>
</rss>

