Delimiter //
/**
 * Author:  armen
 * Created: 21 juil. 2020
 */

Drop Procedure If Exists LOADER_CREDITPROVIDERS_NORMALIZE_MAP_DATE_NOT_PROVIDED//
 
Create Procedure LOADER_CREDITPROVIDERS_NORMALIZE_MAP_DATE_NOT_PROVIDED (
    In batchnum Int
)
Begin
 
    Set @lcpnmpnp_batchnum = batchnum;

    UPDATE
        LOADER_CREDITPROVIDERS_ACCOUNTS lcpa
        Inner Join LOADER_CREDITPROVIDERS lcp
            On lcpa.LDR_CRDTPRVDRS_ID_LDR_CRDTPRVDRS = lcp.ID_LOADER_CREDITPROVIDERS
        INNER JOIN LOADER_STATUS sts
            ON sts.ID_LOADER_STATUS = lcp.LOADER_STATUS_ID_LOADER_STATUS
    SET
        lcp.CREDITS_PROVIDERS_CREATE_DATE = Coalesce(NullIf(lcp.CREDITS_PROVIDERS_CREATE_DATE, '0000-00-00'), CURDATE())

    WHERE 
        sts.LOADER_STATUS_BATCH_NUM = @lcpnmpnp_batchnum
--         AND lcpa.ID_CREDIT_LIMIT_NEW IS NOT NULL
        AND lcpa.ID_CREDITS_PROVIDERS IS NULL
    ;
    
End //
Delimiter ;