<?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>article Qlik Replicate Transformation: Target Lookup - Insert_Date in Official Support Articles</title>
    <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/ta-p/1805653</link>
    <description>&lt;P style="font-style: italic;"&gt;The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.&lt;/P&gt;
&lt;H3 id="toc-hId--525350720"&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;Field Transformation&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;A very common use case for a target table is to have an Insert Date field that populates when the record is initially written. The problem is when the record is updated, the original value in the target is overwritten with null. On my Target table from SQL, I am using the target lookup function under Data Enrichment in order to retrieve the Insert_Date field value during an update operation.&amp;nbsp; When the task table has an Add Column field called Insert-Date and you want to preserve the original date value from when the record was inserted into the target you need to do a target lookup to fetch the original value. In the case of Insert_Date we will use a target lookup function to query the target table and retrieve the field value, putting it into the Add Column that we defined and called Insert_Date. This target lookup function is documented in the replicate user guide and the on-line help.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#339966"&gt;The general form of the function is as follows:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;target_lookup(TTL,'SCHM','TBL','EXP','COND',COND_PARAMS)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;For this example in am doing the lookup into the MLTest table:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;FONT face="courier new,courier"&gt;target_lookup('&lt;SPAN&gt;&lt;SPAN class="ui-provider byh byi c d e f g h i j k l m n o p q r s t byj byk w x y z ab ac ae af ag ah ai aj ak"&gt;NO_CACHING&lt;/SPAN&gt;&lt;/SPAN&gt;','dbo','MLTEST','Insert_Date','EMP_ID=?',$EMP_ID)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NO_CACHING&lt;/FONT&gt; is important to ensure it keeps changing for each value and doesn’t re-use values&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;dbo&lt;/FONT&gt; = target schema&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;MLTEST&lt;/FONT&gt; = target table name&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Insert_Date&lt;/FONT&gt; = the field name&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;EMP_ID&lt;/FONT&gt; = the PK field name for the table in the database syntax&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;$EMP_ID&lt;/FONT&gt; is the replicate internal representation of the PK field for the table&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;That the lookup may have a performance implication and will need to be tested to see if it meets all of your latency criteria.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;You will want to check if the record is being inserted for the first time or updated and only do the lookup if the operation is an Update. The following code shows how to implement this.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;The complete transformation code as follows:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;CASE
WHEN $AR_H_OPERATION = 'INSERT' then
datetime('now')
ELSE
target_lookup (1,'dbo','MLTEST','Insert_Date','EMP_ID=?',$EMP_ID)
END&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This expression is created for the Add Column&amp;nbsp;transformation Insert_Date as seen in the screen shot below.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Target Lookup Insert_Date.PNG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/54401i09E04A2148FBB5C4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Target Lookup Insert_Date.PNG" alt="Target Lookup Insert_Date.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;Unfortunately data enrichment functions can not be tested on the screen, they must be saved and the task run for the transformation to be tested.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&amp;nbsp;Not all target endpoints support the target lookup function. Snowflake does not support&amp;nbsp;this although there is a way to get the same functionality. Please check out the following article:&amp;nbsp;&amp;nbsp;&lt;A href="https://community.qlik.com/t5/Knowledge/Qlik-Replicate-Transformation-column-INSERT-DATETIME-is/ta-p/1949728" target="_blank" rel="noopener"&gt;Qlik Replicate: Transformation column INSERT_DATETIME is overwritten with Null value when record is updated in Snowflake Target&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NOTE:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;The above target lookup uses the SQL server specific &lt;STRONG&gt;"?"&lt;/STRONG&gt; &lt;FONT face="courier new,courier"&gt;'EMP_ID=?'&lt;/FONT&gt;and if you are doing this same lookup into an Oracle database use must use the Oracle specific &lt;STRONG&gt;":"&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'EMP_ID=:'&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H4&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;Environment&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H4&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;LI-PRODUCT title="Qlik Replicate" id="qlikReplicate"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;BR /&gt;Table/Field level transformation&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 12:16:49 GMT</pubDate>
    <dc:creator>Michael_Litz</dc:creator>
    <dc:date>2023-04-26T12:16:49Z</dc:date>
    <item>
      <title>Qlik Replicate Transformation: Target Lookup - Insert_Date</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/ta-p/1805653</link>
      <description>&lt;P&gt;Transformation, Target Lookup, Add Column, Insert_Date field&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 12:16:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/ta-p/1805653</guid>
      <dc:creator>Michael_Litz</dc:creator>
      <dc:date>2023-04-26T12:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Qlik Replicate Transformation: Target Lookup - Insert_Date</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025224#M8159</link>
      <description>&lt;P&gt;Does this date get wiped out when the table is reloaded?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 00:26:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025224#M8159</guid>
      <dc:creator>zacker20</dc:creator>
      <dc:date>2023-01-13T00:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Qlik Replicate Transformation: Target Lookup - Insert_Date</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025226#M8160</link>
      <description>&lt;P&gt;Hi Zacher20,&lt;/P&gt;
&lt;P&gt;Yes, this field value would get cleared/reset when the table was reloaded.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you, &lt;BR /&gt;Michael Litz &lt;BR /&gt;Technical Support Engineer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 00:41:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025226#M8160</guid>
      <dc:creator>Michael_Litz</dc:creator>
      <dc:date>2023-01-13T00:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Qlik Replicate Transformation: Target Lookup - Insert_Date</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025227#M8161</link>
      <description>&lt;P&gt;How would I avoid reloading a table when using sql server ms cdc during a DDL change?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 00:42:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025227#M8161</guid>
      <dc:creator>zacker20</dc:creator>
      <dc:date>2023-01-13T00:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Qlik Replicate Transformation: Target Lookup - Insert_Date</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025228#M8162</link>
      <description>&lt;P&gt;Hi Zacker20,&lt;/P&gt;
&lt;P&gt;There are limitations on DDL's with ms cdc source, so depending on the DDL you may not have to do anything.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Limitations due to the requirement to have MS-CDC enabled on all source tables include:
&lt;UL&gt;
&lt;LI&gt;Rename column is not supported&lt;/LI&gt;
&lt;LI&gt;Truncate table is not supported&lt;/LI&gt;
&lt;LI&gt;WRITETEXT and UPDATETEXT utilities are not supported&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;For more information on MS-CDC limitations, see the Microsoft Help.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Limitations when capturing DDL operations are as follows:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;RENAME TABLE will no be captured. When a RENAME TABLE DDL is encountered, the task will continue capturing the changes without renaming the target table. If the task is stopped and resumed of if there is a recoverable error, the table will be suspended to allow the CT table to be manually aligned.&lt;/LI&gt;
&lt;LI&gt;Table-level DDLs are not supported. When a table DDL is encountered, the DDL will be transferred to the target and the table will be suspended to allow the CT table to be manually aligned.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael Litz&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Technical Support Engineer&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 00:56:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025228#M8162</guid>
      <dc:creator>Michael_Litz</dc:creator>
      <dc:date>2023-01-13T00:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Qlik Replicate Transformation: Target Lookup - Insert_Date</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025232#M8163</link>
      <description>&lt;P&gt;The table level ddls are not transferred to the target because we are using cdc not log based replication.&lt;/P&gt;
&lt;P&gt;wouldn’t I lose data when the table gets suspended&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 01:24:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Replicate-Transformation-Target-Lookup-Insert-Date/tac-p/2025232#M8163</guid>
      <dc:creator>zacker20</dc:creator>
      <dc:date>2023-01-13T01:24:18Z</dc:date>
    </item>
  </channel>
</rss>

