Index: branches/backtrack/ippTools/share/chiptool_pendingimfile.sql
===================================================================
--- branches/backtrack/ippTools/share/chiptool_pendingimfile.sql	(revision 13938)
+++ branches/backtrack/ippTools/share/chiptool_pendingimfile.sql	(revision 13990)
@@ -1,17 +1,29 @@
 SELECT
-    chipPendingExp.*,
+    chipRun.*,
+    chipPendingImfile.exp_tag,
     chipPendingImfile.class_id,
-    chipPendingImfile.uri,
+    rawImfile.uri,
     rawExp.exp_id,
     rawExp.camera,
     rawExp.telescope,
     rawExp.filelevel
-FROM chipPendingImfile
-JOIN chipPendingExp
+FROM chipRun
+JOIN chipPendingImfile
     USING(chip_id)
+LEFT JOIN chipProcessedImfile
+    ON chipPendingImfile.chip_id = chipProcessedImfile.chip_id
+    AND chipPendingImfile.exp_tag = chipProcessedImfile.exp_tag
+    AND chipPendingImfile.class_id = chipProcessedImfile.class_id
+JOIN rawImfile
+    ON chipPendingImfile.exp_tag = rawImfile.exp_tag
+    AND chipPendingImfile.class_id = rawImfile.class_id
 JOIN rawExp
-    ON chipPendingExp.exp_tag = rawExp.exp_tag
+    ON rawImfile.exp_tag = rawExp.exp_tag
 LEFT JOIN chipMask
-    ON chipPendingExp.label = chipMask.label
+    ON chipRun.label = chipMask.label
 WHERE
-    chipMask.label IS NULL
+    chipRun.state = 'run'
+    AND chipProcessedImfile.chip_id IS NULL
+    AND chipProcessedImfile.exp_tag IS NULL
+    AND chipProcessedImfile.class_id IS NULL
+    AND chipMask.label IS NULL
