<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged history-sys_changed-merge</title>
<link>https://overflow.efficy.io/?qa=tag/history-sys_changed-merge</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to detect records that have been deleted during a merge and find the surviving record?</title>
<link>https://overflow.efficy.io/?qa=2356/detect-records-that-deleted-during-merge-surviving-record</link>
<description>&lt;p&gt;When 2 records are merged, there is no clear trace of that merge, saying &quot;this record has been deleted during the merge with THIS record&quot;.&lt;/p&gt;

&lt;p&gt;The only solution I'm thinking about consists in looking at the sys_changed table.&lt;/p&gt;

&lt;p&gt;So if I want to detect if a record has been merged into another one, my idea is to write a function that will search in sys_changed for a record updated by the same user at the same time (+/- 10seconds).&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   CREATE FUNCTION [CUSTOM_MERGED_RECORD](@K_TABLE float, @KEY float)
RETURNS FLOAT AS 
BEGIN
    DECLARE @MERGED_KEY float;
    SELECT @MERGED_KEY = sc2.K_1
    FROM SYS_CHANGED sc
        inner join sys_changed sc2 
            on sc2.k_table = sc.k_table and sc2.USERNAME = sc.USERNAME 
            and sc2.K_1 != sc.K_1 and sc2.OPERATION = 'B' and sc2.K_2 = 0 and sc2.K_3 = 0
    WHERE 
        sc.OPERATION = 'D' and sc.K_TABLE = @K_TABLE AND sc.K_1 = @KEY
        and ABS(DATEDIFF(s, sc.D_CHANGE, sc2.d_change)) &amp;lt; 10

    RETURN @MERGED_KEY
END;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Is there a better solution?&lt;/p&gt;
</description>
<category>Database</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2356/detect-records-that-deleted-during-merge-surviving-record</guid>
<pubDate>Mon, 13 Mar 2017 16:12:01 +0000</pubDate>
</item>
</channel>
</rss>