Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 29665)
+++ trunk/ippTools/src/difftool.c	(revision 29696)
@@ -2009,20 +2009,15 @@
     if (psListLength(stack1Where->list)) {
 	psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL);
-	psStringAppend(&stack1Query, "\n AND %s", whereClause);
+	psStringAppend(&stack1Query, "AND %s", whereClause);
 	psFree(whereClause);
-    } else {
-	stack1Query = psStringCopy("\n");
-    }
+    } 
     psFree(stack1Where);
 
     if (psListLength(stack2Where->list)) {
 	psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL);
-	psStringAppend(&stack2Query, "\n AND %s", whereClause);
+	psStringAppend(&stack2Query, "AND %s", whereClause);
 	psFree(whereClause);
-    } else {
-	stack2Query = psStringCopy("\n");
-    }
+    } 
     psFree(stack2Where);
-
   
     // don't queue for stacks that have already been diffed unless requested
@@ -2030,10 +2025,7 @@
     psString diffQuery1 = NULL;
     if (! (reRun || newTemplates) ) {
-	psStringAppend(&diffQuery0, "\n AND diffExp.diff_id IS NULL");
-	psStringAppend(&diffQuery1, "\n AND n_diff = 0");
-    } else {
-	diffQuery0 = psStringCopy("\n");
-	diffQuery1 = psStringCopy("\n");
-    }
+	psStringAppend(&diffQuery0, "AND diffExp.diff_id IS NULL");
+	psStringAppend(&diffQuery1, "HAVING n_diff = 0");
+    } 
 
     // find the distinct set of data_groups and filters
@@ -2049,5 +2041,4 @@
 	return(false);
     }
-
 
     psString queryCopy = psStringCopy(query);
@@ -2127,7 +2118,6 @@
 	psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL);
 	psStringSubstitute(&thisWhere,"stackRun.","INPUT_");
-	psStringAppend(&this_stack1Query,"\n AND %s", thisWhere);
+	psStringAppend(&this_stack1Query,"AND %s", thisWhere);
 	psFree(thisWhere);
-
 
 	psString queryCopy = psStringCopy(query);
@@ -2146,5 +2136,5 @@
 	}
 
-	if (!p_psDBRunQueryF(config->dbh, query, stack2Query, this_stack1Query, diffQuery1, this_stack1Query)) {
+	if (!p_psDBRunQuery(config->dbh, query)) {
 	    psError(PS_ERR_UNKNOWN, false, "database error");
 	    psFree(query);
