Delimiter //
/**
* 
**/

Drop Procedure if exists LOADER_ATTACHEDMEMBERS_NORMALIZE_CHECK_MEMBERS_EXISTS//

Create Procedure LOADER_ATTACHEDMEMBERS_NORMALIZE_CHECK_MEMBERS_EXISTS (
    In batchnum int
)
Begin
    Set @query = null;
	call LOADER_BUILD_CHECK_BASE_QUERY('LOADER_ATTACHEDMEMBERS'
                                    , '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 ;