diff --git a/aql2/src/aql.cpp b/aql2/src/aql.cpp
index 1b7403027fdab4a6bb74faacfcf0e4feb053e7ee..2b697ea38f62787cb724455bf0d97900cfd20fb4 100644
--- a/aql2/src/aql.cpp
+++ b/aql2/src/aql.cpp
@@ -88,10 +88,14 @@ int main ( int argc, char * argv[] ) {
 		if ( queries.getValue ( ).empty ( ) ) {
 			result = p.run ( );
 		} else {
-			for ( const std::string & query : queries.getValue ( ) )
-				p.execute_line ( query );
-
-			result = cli::Command::Result::QUIT;
+			for ( const std::string & query : queries.getValue ( ) ) {
+				result = p.execute_line ( query );
+				if ( result != cli::Command::Result::OK )
+					break;
+			}
+
+			if ( result == cli::Command::Result::OK )
+				result = cli::Command::Result::QUIT;
 		}
 
 		measurements::end ( );