Delimiter //
/**
	procédure stoké qui permet de construire le corp des requete de vérification pour les comptes

	In checkedFieldName : le nom du champ à vérifier
	In batchnum : numero de lot
    In lastStatusFieldName
    In lastStatus
    isWarning : 
        0 : maj des champs error
        1 : maj des champs warning
	out query : la requête généré
*/
Drop Procedure if exists LOADER_BUILD_ACCOUNTS_CHECK_BASE_QUERY//

Create Procedure LOADER_BUILD_ACCOUNTS_CHECK_BASE_QUERY (
	In checkedFieldName varchar(70)
	, In batchnum int
    , In flagMsg varchar(50)
	, In lastStatus varchar(150)
    , In isWarning tinyint
	, out query text
)
Begin
    Set @flagCountField='LOADER_ACCOUNTS_ERRCOUNT';
    Set @flagMsgField='LOADER_ACCOUNTS_ERRMSGS';
    Set @lastStatusField=null;
    Set @lastStatus=null;

    if Coalesce(isWarning, 0) = 1 Then
        Set @flagCountField='LOADER_ACCOUNTS_WARNCOUNT';
        Set @flagMsgField='LOADER_ACCOUNTS_WARNMSGS';
        Set @lastStatusField='';
        Set @lastStatus=lastStatus;
    End if ;


    call LOADER_BUILD_CHECK_BASE_QUERY ('LOADER_ACCOUNTS', checkedFieldName,
                    'LOADER_ACCOUNTS_BATCH_NUM', batchnum, 
                    @flagCountField, @flagMsgField, flagMsg, 
                    @lastStatusField, @lastStatus,
                    query
        );

End //
Delimiter ;
