
Delimiter //
Drop Procedure if exists LOADER_BUILD_EDMINDEX_CHECK_BASE_QUERY//

Create Procedure LOADER_BUILD_EDMINDEX_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_EDMINDEX_ERRCOUNT';
    Set @flagMsgField='LOADER_EDMINDEX_ERRMSGS';
    Set @lastStatusField=null;
    Set @lastStatus=null;

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


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

End //
Delimiter ;
