Delimiter //
/**
 *
 */ 
Drop Procedure if Exists LOADER_LINKEDACCOUNTS_NORMALIZE_MAP_LINK_EXISTS//
Create Procedure LOADER_LINKEDACCOUNTS_NORMALIZE_MAP_LINK_EXISTS (
    In batchnum int
)
Begin
	Update LOADER_LINKEDACCOUNTS LNKAC
		Inner Join ACCOUNTS_has_ACCOUNTS src
			On LNKAC.ACCOUNTS_ID_ACCOUNTS = src.ACCOUNTS_ID_ACCOUNTS
			And LNKAC.ACCOUNTS_ID_ACCOUNTS_LINKED = src.ACCOUNTS_ID_ACCOUNTS_LINK
		Inner Join LOADER_STATUS lst
			On LNKAC.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS
	Set
		LNKAC.ID_ACCOUNTS_has_ACCOUNTS = src.ID_ACCOUNTS_has_ACCOUNTS
	Where
		lst.LOADER_STATUS_BATCH_NUM = batchnum
		And LNKAC.ID_ACCOUNTS_has_ACCOUNTS Is null
	;
End //
Delimiter ;