<?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: DYNAMIC update statement preparation in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321360#M91399</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I will try to detail as much as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understood correctly, you want to create dynamic DMLs according to the data, the columns, the input tables!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first step is to centralize the metadata, ie, retrieve and control the names of tables, columns and primary keys. You can use https://dataedo.com/kb/query/mysql/list-tables-with-their-primary-keys for example or another database system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second step is to get the columns from the CSV files. so either you provide them as a parameter (if it doesn't change often) or you can read the first line of the file and normalize eg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step is to detect changes in your data. so, there the tMap is your friend and you get the rejection of join or others; it's up to you to define how you want to detect changes. you can use a comparison on a date, or temporary table,  with an except, ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last is to build your DML, here is an example code using a column list and data. you can draw inspiration from it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's just an algo, actually you will use a tFlowToIterate to store each value of your columns in memory then a tJava to construct your query, finally you concatenate everything or you execute it with a tDBRow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;String UpdateStatement =" Update " + context.Target_Table + "&amp;nbsp;SET&amp;nbsp;";&lt;/P&gt;&lt;P&gt;String WhereClause ="&amp;nbsp;Where ";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; columns.getColumnCount(); i++) {&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;	&lt;/P&gt;&lt;P&gt;&amp;nbsp;UpdateStatement= UpdateStatement + " " + column.getName() +"='" +columns.getColumnValue(i) +"', ";&lt;/P&gt;&lt;P&gt;&amp;nbsp;WhereClause += context.Target_Table+"."+column.getName() +"='"+&amp;nbsp;columns.getColumnValue(i)+"'";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;context.Update_Query =&amp;nbsp;UpdateStatement + WhereClause;&lt;/P&gt;</description>
    <pubDate>Sun, 31 Jan 2021 20:58:38 GMT</pubDate>
    <dc:creator>JohnRMK</dc:creator>
    <dc:date>2021-01-31T20:58:38Z</dc:date>
    <item>
      <title>DYNAMIC update statement preparation</title>
      <link>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321357#M91396</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a scenario to create dynamic update statement as output.&lt;/P&gt;&lt;P&gt;table 1:&lt;/P&gt;&lt;P&gt;identifier tablename updfield keycolname&lt;/P&gt;&lt;P&gt;US CUSTOMER code, age acctno,date&lt;/P&gt;&lt;P&gt;ET INS name date&lt;/P&gt;&lt;P&gt;table2:&lt;/P&gt;&lt;P&gt;identifier updfiledvalue keycolvalue&lt;/P&gt;&lt;P&gt;US 99,'24F' 2525,'2017-01-14'&lt;/P&gt;&lt;P&gt;ET 'som' '2014-12-12'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output file should look like this:&lt;/P&gt;&lt;P&gt;---Need update statement script as output records&lt;/P&gt;&lt;P&gt;update &amp;lt;&amp;gt;;&lt;/P&gt;&lt;P&gt;update &amp;lt;&amp;gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;like below based on above value&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;update statement of first record&amp;gt;&lt;/P&gt;&lt;P&gt;UPDATE CUSTOMER&lt;/P&gt;&lt;P&gt;SET CODE=99, AGE='24F'&lt;/P&gt;&lt;P&gt;WHERE&lt;/P&gt;&lt;P&gt;ACCTNO=2525 AND DATE='&lt;/P&gt;&lt;P&gt;'2017-01-14';&lt;/P&gt;&lt;P&gt;&amp;lt;update statement of second record&amp;gt;&lt;/P&gt;&lt;P&gt;scenarios:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;the number of columns to get updated is based on table entry(may be one or more than 1 column based on entry)&lt;/LI&gt;&lt;LI&gt;the number of keycolumns in where clause is also based on table entry&lt;/LI&gt;&lt;LI&gt;identifier is common column for both table&lt;/LI&gt;&lt;LI&gt;i may have many update for single identifier&lt;/LI&gt;&lt;LI&gt;if same entries are to be updated again, we must omit that&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;can anyone please help me on this.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 00:44:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321357#M91396</guid>
      <dc:creator>Nan1</dc:creator>
      <dc:date>2024-11-16T00:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: DYNAMIC update statement preparation</title>
      <link>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321358#M91397</link>
      <description>&lt;P&gt;This is an interesting situation. &lt;/P&gt;&lt;P&gt;Because your to-be updated columns keep changing, I would create a view on the fly using tDBRow and try to update that view instead of a table. When I had performance issues in one of my earlier jobs where I was using SCD, I used this approach and it works like a charm. The catch here is, for your view definition to change for every incoming row, you have to use an iterator, if not your view definition will not change. Additionally you have to take in to consider the performance impact, because if you want a DDL to be triggered for every incoming row then it does add a lot of overhead to the process.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 17:17:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321358#M91397</guid>
      <dc:creator>tnewbie</dc:creator>
      <dc:date>2021-01-27T17:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: DYNAMIC update statement preparation</title>
      <link>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321359#M91398</link>
      <description>&lt;P&gt;i need the method/job flow of achieving this. can anyone please help&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 06:42:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321359#M91398</guid>
      <dc:creator>Nan1</dc:creator>
      <dc:date>2021-01-28T06:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: DYNAMIC update statement preparation</title>
      <link>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321360#M91399</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I will try to detail as much as possible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I understood correctly, you want to create dynamic DMLs according to the data, the columns, the input tables!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first step is to centralize the metadata, ie, retrieve and control the names of tables, columns and primary keys. You can use https://dataedo.com/kb/query/mysql/list-tables-with-their-primary-keys for example or another database system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second step is to get the columns from the CSV files. so either you provide them as a parameter (if it doesn't change often) or you can read the first line of the file and normalize eg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step is to detect changes in your data. so, there the tMap is your friend and you get the rejection of join or others; it's up to you to define how you want to detect changes. you can use a comparison on a date, or temporary table,  with an except, ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last is to build your DML, here is an example code using a column list and data. you can draw inspiration from it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's just an algo, actually you will use a tFlowToIterate to store each value of your columns in memory then a tJava to construct your query, finally you concatenate everything or you execute it with a tDBRow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;String UpdateStatement =" Update " + context.Target_Table + "&amp;nbsp;SET&amp;nbsp;";&lt;/P&gt;&lt;P&gt;String WhereClause ="&amp;nbsp;Where ";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for (int i = 0; i &amp;lt; columns.getColumnCount(); i++) {&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;	&lt;/P&gt;&lt;P&gt;&amp;nbsp;UpdateStatement= UpdateStatement + " " + column.getName() +"='" +columns.getColumnValue(i) +"', ";&lt;/P&gt;&lt;P&gt;&amp;nbsp;WhereClause += context.Target_Table+"."+column.getName() +"='"+&amp;nbsp;columns.getColumnValue(i)+"'";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;context.Update_Query =&amp;nbsp;UpdateStatement + WhereClause;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Jan 2021 20:58:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/DYNAMIC-update-statement-preparation/m-p/2321360#M91399</guid>
      <dc:creator>JohnRMK</dc:creator>
      <dc:date>2021-01-31T20:58:38Z</dc:date>
    </item>
  </channel>
</rss>

