<?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: DI Studio SQL Merge Transformation User Guide in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896228#M20864</link>
    <description>It unclear what the problem is</description>
    <pubDate>Thu, 28 Sep 2023 10:27:48 GMT</pubDate>
    <dc:creator>rudfaden</dc:creator>
    <dc:date>2023-09-28T10:27:48Z</dc:date>
    <item>
      <title>DI Studio SQL Merge Transformation User Guide</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896199#M20863</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not a big user of DI Studio, but find myself in a scenario where I need to use the SQL Merge Transformation, to update and insert records in an SCD2 Oracle Table.&amp;nbsp; I have worked my way through the user guide and have really not found much information on this transformation.&amp;nbsp; I have read this article&amp;nbsp;&lt;A href="http://databobjr.blogspot.com/2011/04/load-slowly-changing-dimension-type-2.html," target="_blank" rel="noopener"&gt;http://databobjr.blogspot.com/2011/04/load-slowly-changing-dimension-type-2.html,&lt;/A&gt;&amp;nbsp;which has given me a lot of insight into how the code should be structured, but having taken a number of stabs at replicating the logic in DI, I have failed miserably.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have searched Google (of course), but I am yet to find anything that addresses this topic at length.&amp;nbsp; Does anyone have good resources around how to use this transformation at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any assistance offered.&lt;BR /&gt;&lt;BR /&gt;Edit: This is what I have been able to come up with so far.&amp;nbsp; It appears the problem I am having is getting the subqueries to nest correctly.&amp;nbsp; This is the code I have generated so far:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MERGE INTO dim_product p
USING ( SELECT DECODE(s.scd_row_type_id,1,-6789,m.product_sid) as product_sid,
                   PRODUCT_ID,
                   PRODUCT_CATEGORY_ID,
                   PRODUCT_NAME,
                   PRODUCT_DESCRIPTION,
                   PRICE,
                   PRICE_EFFECTIVE_DATE,
                   LAST_MODIFIED_DATE,
                   CREATED_DATE,
                   m.scd_row_type_id
              FROM    (SELECT dp.product_sid,
                              sp.PRODUCT_ID,
                              sp.PRODUCT_CATEGORY_ID,
                              sp.PRODUCT_NAME,
                              sp.PRODUCT_DESCRIPTION,
                              sp.PRICE,
                              sp.PRICE_EFFECTIVE_DATE,
                              sp.LAST_MODIFIED_DATE,
                              sp.CREATED_DATE,
                              CASE
                                 WHEN dp.product_id IS NULL
                                 THEN
                                    1
                                 WHEN (dp.product_category_id !=
                                          sp.product_category_id
                                       OR dp.product_name != sp.product_name
                                       OR DP.PRODUCT_DESCRIPTION !=
                                             sp.product_description
                                       OR dp.price != sp.price
                                       OR dp.price_effective_date !=
                                             sp.price_effective_date)
                                 THEN
                                    2
                                 ELSE
                                    0
                              END
                                 AS scd_row_type_id
                         FROM    stg_product sp
                              LEFT JOIN
                                 Dim_product dp
                              ON (sp.product_id = dp.product_id and  dp.is_current_row = 'Y')
                     ) m
                   JOIN  scd_row_type s
                   ON (s.scd_row_type_id &amp;lt;= m.scd_row_type_id)
                   ) mp
        ON  (p.product_sid = mp.product_sid)
when matched then
   update set P.EFFECTIVE_END_DATE = mp.LAST_MODIFIED_DATE, is_current_row = 'N', updated_date = sysdate
  commit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 07:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896199#M20863</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2023-09-28T07:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio SQL Merge Transformation User Guide</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896228#M20864</link>
      <description>It unclear what the problem is</description>
      <pubDate>Thu, 28 Sep 2023 10:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896228#M20864</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2023-09-28T10:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: DI Studio SQL Merge Transformation User Guide</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896230#M20865</link>
      <description>&lt;P&gt;I haven't used the Merge transformation that much, but it's quite straight forward - but it's' linked to the syntax of SQL MERGE statement, so you need to know what you want to do.&lt;/P&gt;
&lt;P&gt;Why do you have to use the Merge transformation?&lt;/P&gt;
&lt;P&gt;if you are updating a SCD Type 2 table, there's a transformation for that...&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 10:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/DI-Studio-SQL-Merge-Transformation-User-Guide/m-p/896230#M20865</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-09-28T10:50:17Z</dc:date>
    </item>
  </channel>
</rss>

