<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Efficy Overflow Q&amp;A - Recent questions tagged sys_changed-d_change-changedby</title>
<link>https://overflow.efficy.io/?qa=tag/sys_changed-d_change-changedby</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to recover the date and user of the last modification after a data synchro</title>
<link>https://overflow.efficy.io/?qa=2711/how-recover-date-user-last-modification-after-data-synchro</link>
<description>&lt;p&gt;I performed a data realignment datasynchro of documents to update one field.&lt;br&gt;
Consequently, the date of last modification (D_CHANGE) as well as the code of the user who performed the last modification (CHANGEDBY) are (almost) lost.&lt;/p&gt;

&lt;p&gt;I wrote a statement to recover these 2 values.&lt;br&gt;
Can anybody (comfortable with sql statements) validate my statement?&lt;br&gt;
Is there a simpler way to achieve this recovery?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;update documents d set 
D_CHANGE = (
  SELECT d_change from ( -- Before Last date of update or insertion of the record
    select ROWNUM AS RNUM, sc.*  
    from
    (
      select sc.d_change
      from SYS_CHANGED sc 
      where k_table = 31000 and k_1 = d.K_DOCUMENT
      and operation in ('B', 'A') -- UPDATE OR INSERT
      order by d_change, milli desc
    ) sc
  )
  where RNUM = 2 -- Before Last INSERT or UPDATE operation
),
CHANGEDBY = (
  SELECT username as username from ( -- Before Last user that updated or inserted the record
    select ROWNUM AS RNUM, sc.* 
    from
    (
      select sc.username
      from SYS_CHANGED sc 
      where k_table = 31000 and k_1 = d.K_DOCUMENT
      and operation in ('B', 'A') -- UPDATE OR INSERT
      order by d_change, milli desc
    ) sc
  )
  where RNUM = 2 -- Before Last INSERT or UPDATE operation
)
where k_document in ( -- Select document keys linked to my publication, for which the last modification has been done by the admin user
    select d.K_DOCUMENT 
    from docu_publ dp
    inner join documents d on d.K_document = dp.K_document
    where dp.k_publication = 4394 and d.changedby = 'ADMINEBIS'
);
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Database</category>
<guid isPermaLink="true">https://overflow.efficy.io/?qa=2711/how-recover-date-user-last-modification-after-data-synchro</guid>
<pubDate>Fri, 29 Sep 2017 15:36:55 +0000</pubDate>
</item>
</channel>
</rss>