Delimiter //
/**
 * Author:  armen
 * Created: 21 juil. 2020
 */
Drop Procedure If Exists LOADER_CREDITPROVIDERS_CREDITSPROVIDERS_UPDATE//

Create Procedure LOADER_CREDITPROVIDERS_CREDITSPROVIDERS_UPDATE (
    In batchnum Int
)
Begin
    Set @lcpcpu_batchnum = batchnum;
    Update 
        CREDITS_PROVIDERS tar
        Inner Join LOADER_CREDITPROVIDERS_ACCOUNTS src  
            On tar.ID_CREDITS_PROVIDERS = src.ID_CREDITS_PROVIDERS
        Inner Join LOADER_CREDITPROVIDERS tbl1  
            On src.LDR_CRDTPRVDRS_ID_LDR_CRDTPRVDRS = tbl1.ID_LOADER_CREDITPROVIDERS
        Inner Join LOADER_STATUS lst  
            On src.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS  
    Set
    -- la date val ne dois plus être pas mise à jour dans l'import
    -- la normalisation créer des donnée à ajouter si nécéssaire
--         tar.CREDITS_PROVIDERS_VAL_DATE = SUBDATE(CURDATE(), 1) -- Validity date update only
        tar.CREDITS_PROVIDERS_LABEL = Coalesce(tbl1.CREDITS_PROVIDERS_LABEL, tar.CREDITS_PROVIDERS_LABEL)
        , tar.CREDITS_PROVIDERS_COMMENT = Coalesce(tbl1.CREDITS_PROVIDERS_COMMENT, tar.CREDITS_PROVIDERS_COMMENT)
        , tar.CREDITS_PROVIDERS_CREDIT_LIMIT = Coalesce(tbl1.CREDITS_PROVIDERS_CREDIT_LIMIT, tar.CREDITS_PROVIDERS_CREDIT_LIMIT)
        , tar.CREDITS_PROVIDERS_SCORE = Coalesce(tbl1.CREDITS_PROVIDERS_SCORE, tar.CREDITS_PROVIDERS_SCORE)
    Where lst.LOADER_STATUS_ERRCOUNT = 0  
        And src.ID_CREDITS_PROVIDERS Is Not Null
        And lst.LOADER_STATUS_BATCH_NUM = @lcpcpu_batchnum
        And tbl1.LOADER_CREDITPROVIDERS_ROW_REJECTED = 0
    ;

End //

Delimiter ;
