Delimiter //
/**
* 
**/

Drop Procedure if exists LOADER_MEMBERSACCRED_NORMALIZE_CHECK_MEMBERS_EXISTS//

Create Procedure LOADER_MEMBERSACCRED_NORMALIZE_CHECK_MEMBERS_EXISTS (
    In batchnum int
)
Begin
    Set @query = null;
	call LOADER_BUILD_CHECK_BASE_QUERY('LOADER_MEMBERSACCRED'
                                    , 'MEMBERS_LOGIN,CONTACTS_REF'
                                    , 'LOADER_STATUS_BATCH_NUM', batchnum, 'ERRCOUNT', 'ERRMSGS'
                                    , 'Member not found', null, null
                                    , @query
                                )
                            ;
	set @query = Concat(@query, ' And ( trgt.ID_MEMBERS Is Null ) And ( STS.LOADER_STATUS_ERRCOUNT = 0)');
	PREPARE stmt FROM @query;
	execute stmt			
		;
	Deallocate prepare stmt;
End //
Delimiter ;