Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 9328)
+++ /trunk/ippTools/src/dettool.c	(revision 9329)
@@ -2176,7 +2176,7 @@
         "     ON detInputExp.det_id = detStackedImfile.det_id"
         "     AND detInputExp.iteration = detStackedImfile.iteration"
-        " LEFT JOIN detNormlaizedStatImfile"
+        " LEFT JOIN detNormalizedStatImfile"
         "     ON detRun.position = detNormalizedStatImfile.det_id"
-        "     ON detRun.iteration = detNormalizedStatImfile.iteration"
+        "     AND detRun.iteration = detNormalizedStatImfile.iteration"
         " WHERE"
         "   detRun.state = 'run'"
@@ -2185,4 +2185,5 @@
         " GROUP BY"
         "     rawDetrendExp.exp_tag,"
+        "     detRun.iteration,"
         "     detRun.position"
         " HAVING MAX(rawDetrendExp.imfiles) = COUNT(detStackedImfile.class_id)"
@@ -3797,16 +3798,17 @@
         if (!status) {
             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
+            return false;
+        }
+        if (!det_id) {
+            psError(PS_ERR_UNKNOWN, true, "-det_id is required");
+            return false;
+        }
+        if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==", (psS32)atoi(det_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
             psFree(where);
             psFree(query);
             return false;
         }
-        if (det_id) {
-            if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
-                psFree(where);
-                psFree(query);
-                return false;
-            }
-        }
+
         psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
         if (!status) {
