diff --git a/modules/Migration/schema/660_to_700.php b/modules/Migration/schema/660_to_700.php
index 4d37e1f5b1af6fba5baacec7c94cb6bd455823be..e65117aee657f086534e569b7bab8e18754a86b7 100644
--- a/modules/Migration/schema/660_to_700.php
+++ b/modules/Migration/schema/660_to_700.php
@@ -623,9 +623,9 @@ if(defined('VTIGER_UPGRADE')) {
 	do {
 		$commentsResult = $db->pquery('SELECT vtiger_modcomments.modcommentsid FROM vtiger_modcomments 
 												LEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_modcomments.related_to 
-												WHERE vtiger_crmentity.setype NOT IN ('.generateQuestionMarks($internalCommentModules).') 
-												OR vtiger_crmentity.setype IS NULL AND modcommentsid > ? LIMIT 500', array_merge($internalCommentModules, array($lastMaxCRMId)));
-		if (!$db->num_rows($result)) {
+												WHERE (vtiger_crmentity.setype NOT IN ('.generateQuestionMarks($internalCommentModules).') 
+												OR vtiger_crmentity.setype IS NULL) AND modcommentsid > ? LIMIT 500', array_merge($internalCommentModules, array($lastMaxCRMId)));
+		if (!$db->num_rows($commentsResult)) {
 			break;
 		}
 
@@ -645,7 +645,7 @@ if(defined('VTIGER_UPGRADE')) {
 		$commentsResult = NULL;
 		unset($commentsResult);
 	} while (true);
-	
+
 	//Start - Add Contact Name to Default filter of project
 	$cvidQuery = $db->pquery('SELECT cvid FROM vtiger_customview where viewname=? AND entitytype=?', array('All', 'Project'));
 	$row = $db->fetch_array($cvidQuery);