Updating table with procedure on column where last date is
<p>I can't figure out how to create a procedure that only updates table automatically.</p>

<p>What I am trying to do is update table into db.New_table from yesterday date on SENDDATE aka. table has all the information from 01.01.1998 till 09.01.2016, but need to create automated procedure to update that table automatically </p>

<pre><code>SELECT 
account.STRING0,
activity.CONTACT,
account.STRING2,
activity.TEMPLATE,
activity.NAME ,
val1.type_code,
val2.type_name,
activity.EXECUTION, 
activity.SENDDATE,
Activity.OPENDATE,
Activity.CLICKDATE
into db.New_table
FROM  
    db.1_account account 
Join 
    db.2_activity activity 
    ON 
     (account.object = activity.contact)
 left JOIN 
    db.VAL val1 
       ON val1.obj_row_id = activity.CAMPAIGN AND (val1.FIELD in(850)) 
left JOIN 
    db.VAL val2 
       ON val2.obj_row_id = activity.CAMPAIGN AND (val2.FIELD in(851))
Commit
End
</code></pre>

<p>Guy who left the company sent me example, but he did not have the time to explain to me how to use that query.</p>

<pre><code>ALTER PROCEDURE "DWTMP"."LOAD_CHANGED_VALUES"()
AS
BEGIN

insert into DW_TMP.DW_TRANSFER_LOG (TRANSFER_CODE, TABLE_NAME, LOG_DATE_TIME, LOG_DATE, OPERATION, LOG_TEXT) 
SELECT 'LOAD_CHANGED_VALUES', 'TMP_CHANGED_RES', GETDATE(), DATE(GETDATE()), 'START', 'Transfer started'
COMMIT

DECLARE @TRANSFER_STAMP TIMESTAMP
SET @TRANSFER_STAMP = GETDATE()
DECLARE @TRANSFER_STAMP1 TIMESTAMP
SET @TRANSFER_STAMP1 = GETDATE()

TRUNCATE TABLE DW_TMP.tmp_changed_res
insert into dw_tmp.tmp_changed_res(res_id, modified_date_time, modifier_CODE)
select rh.res_id, rh.trans_timestamp as modified_date_time , rh.performer as modifier_CODE
        from SE.RES_HISTORY RH
        join    (SELECT RES_ID, MAX(TRANS_ID) TRANS_ID 
                    from SE.RES_HISTORY RH
                    JOIN DW_TMP.PAR_LASTTRANSFER LT
                        ON LT.TABLE_CODE = 'RESERVATION'
                WHERE RH.TRANS_TIMESTAMP BETWEEN DATEADD(HOUR,-1,LT.FROM_TRANSFER_DATE) AND TO_TRANSFER_DATE
                    AND RH.TRANS_TIMESTAMP &lt; DATEADD(MINUTE,-5,@TRANSFER_STAMP)
                GROUP BY RES_ID) t
            on rh.res_id = t.res_id
            and rh.trans_id = t.trans_id
</code></pre>

<p>NB!SQL Server (Sybase)</p>

<p>Visual data flow<a href="https://i.stack.imgur.com/tXr3g.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tXr3g.jpg" alt="Visual data flow"></a></p>