Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 12422)
+++ trunk/ippTools/src/dettool.c	(revision 12424)
@@ -5497,32 +5497,9 @@
     // compare the counts of exp_tags
 
-    psString query = psStringCopy(
-        "SELECT DISTINCT\n"
-        "   det_id,\n"
-        "   iteration\n"
-        " FROM\n"
-        "   (SELECT DISTINCT\n"
-        "       detRun.det_id,\n"
-        "       detRun.iteration,\n"
-        "       detInputExp.exp_tag\n"
-        "   FROM detRun\n"
-        "       LEFT JOIN detInputExp\n"
-        "       ON detRun.det_id = detInputExp.det_id\n"
-        "       AND detRun.iteration = detInputExp.iteration\n"
-        "   LEFT JOIN rawExp\n"
-        "       ON detInputExp.exp_tag = rawExp.exp_tag\n"
-        "   LEFT JOIN detResidExp\n"
-        "       ON detRun.det_id = detResidExp.det_id\n"
-        "       AND detRun.iteration = detResidExp.iteration\n"
-        "       AND detInputExp.exp_tag = detResidExp.exp_tag\n"
-        "   WHERE\n"
-        "       detRun.state = 'run'\n"
-        "   GROUP BY\n"
-        "       detRun.det_id,\n"
-        "       detRun.iteration\n"
-        "   HAVING\n"
-        "       COUNT(detResidExp.exp_tag) = COUNT(detInputExp.exp_tag)\n"
-        " ) AS residdetrun\n"
-        );
+    psString query = pxDataGet("dettool_find_completed_runs.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
 
     {
