使用上一个日期所在列的过程更新表

时间:2016-01-11 07:30:59

标签: sql sybase sqlanywhere sybase-iq

我无法弄清楚如何创建一个只自动更新表的过程。

我要做的是从SENDDATE aka上的昨天日期将表更新到db.New_table。 table包含从01.01.1998到2016年1月9日的所有信息,但需要创建自动更新该表的自动程序

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

离开公司的家伙给我示例,但他没有时间向我解释如何使用该查询。

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 < DATEADD(MINUTE,-5,@TRANSFER_STAMP)
                GROUP BY RES_ID) t
            on rh.res_id = t.res_id
            and rh.trans_id = t.trans_id

NB!SQL Server(Sybase)

可视化数据流Visual data flow

0 个答案:

没有答案