Delimiter //
/**
 * Credit limit data update => history
 * @param int batchnum
 * @author Ben
 */
Drop Procedure If Exists LOADER_CREDITLIMIT_CREDITLIMIT_UPDATE//

Create Procedure LOADER_CREDITLIMIT_CREDITLIMIT_UPDATE (
    In batchnum Int
)
Begin
    Set @lccu_batchnum = batchnum;
--     Update 
--         CREDIT_LIMIT tar
--         Inner Join LOADER_CREDITLIMIT src  
--             On tar.ID_CREDIT_LIMIT = src.ID_CREDIT_LIMIT
--         Inner Join LOADER_STATUS lst  
--             On src.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS  
--     Set
--         tar.CREDIT_LIMIT_VAL_DATE = SUBDATE(CURDATE(), 1) -- Validity date update only
--     Where 1 = 1  
--         And lst.LOADER_STATUS_ERRCOUNT = 0  
--         And lst.LOADER_STATUS_BATCH_NUM =  batchnum
--     ;
    Update 
        CREDIT_LIMIT tar
        Inner Join LOADER_CREDITLIMIT_ACCOUNTS src  
            On tar.ID_CREDIT_LIMIT = src.ID_CREDIT_LIMIT
        Inner Join LOADER_STATUS lst  
            On src.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS  
    Set
        tar.CREDIT_LIMIT_VAL_DATE = SUBDATE(CURDATE(), 1) -- Validity date update only
    Where lst.LOADER_STATUS_ERRCOUNT = 0  
        And lst.LOADER_STATUS_BATCH_NUM = @lccu_batchnum
    ;

End //

Delimiter ;
