Delimiter //
/**
 * Author:  armen
 * Created: 31 janv. 2018
 */
Drop Procedure if exists LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_UPDATE//

Create Procedure LOADER_MEMBERSACCRED_ENTITIES_HAS_MBR_UPDATE (
    In batchnum int
)
Begin

        Update ENTITIES_has_MEMBERS tar
        Inner Join (
                LOADER_STATUS sts 
                Inner Join LOADER_MEMBERSACCRED src
                    On src.LOADER_STATUS_ID_LOADER_STATUS = sts.ID_LOADER_STATUS
            ) On tar.ID_ENTITIES_has_MEMBERS = src.ID_ENTITIES_has_MEMBERS
        Set
            tar.DF_ACCESS_PROFILES_ID_DF_ACCESS_PROFILES = src.DF_ACCESS_PROFILES_ID_DF_ACCESS_PROFILES
            , tar.DF_FUNCTIONS_ID_DF_FUNCTIONS = src.DF_FUNCTIONS_ID_DF_FUNCTIONS
        Where
            sts.LOADER_STATUS_ERRCOUNT = 0 
            And src.ID_ENTITIES_has_MEMBERS_NEW Is Null
            And src.ID_ENTITIES_has_MEMBERS Is Not Null
            And sts.LOADER_STATUS_BATCH_NUM = batchnum
        ;
End //

Delimiter ;