Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 28853)
+++ trunk/ippTools/share/Makefile.am	(revision 28856)
@@ -6,4 +6,5 @@
 	addtool_checkminidvodbaddrun.sql \
 	addtool_donecleanup.sql \
+	addtool_find_cam_id_dvo.sql \
 	addtool_find_cam_id.sql \
 	addtool_find_pendingexp.sql \
Index: trunk/ippTools/share/addtool_find_cam_id_dvo.sql
===================================================================
--- trunk/ippTools/share/addtool_find_cam_id_dvo.sql	(revision 28856)
+++ trunk/ippTools/share/addtool_find_cam_id_dvo.sql	(revision 28856)
@@ -0,0 +1,10 @@
+SELECT camRun.* FROM camRun
+JOIN chipRun USING(chip_id)
+JOIN rawExp USING(exp_id)
+WHERE camRun.state = 'full'
+    AND exp_id NOT IN (SELECT exp_id
+       FROM addRun
+       JOIN camRun USING(cam_id)
+       JOIN chipRun USING(chip_id)
+       WHERE %s
+      )
Index: trunk/ippTools/src/addtool.c
===================================================================
--- trunk/ippTools/src/addtool.c	(revision 28853)
+++ trunk/ippTools/src/addtool.c	(revision 28856)
@@ -144,23 +144,25 @@
     PXOPT_LOOKUP_BOOL(simple,     config->args, "-simple", false);
 
-
-
-    // find the cam_id of all the exposures that we want to queue up.
-    psString bare_query = pxDataGet("addtool_find_cam_id.sql");
-    if (!bare_query) {
-        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-        psFree(where);
-        return false;
-    }
-
     // prevent queueing an addRun if a given exposure has already been added to
     // the given dvo database
     psString dvodb_string = NULL;
+    psString bare_query = NULL;
     if (dvodb) {
-        // user supplied dvodb
-        psStringAppend(&dvodb_string, "(previous_dvodb = '%s')", dvodb);
+      psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_cam_id_dvo.sql\n", dvodb);
+        // find the cam_id of all the exposures that we want to queue up.
+        bare_query = pxDataGet("addtool_find_cam_id_dvo.sql");
+	// user supplied dvodb
+	psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
     } else {
+        psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_cam_id.sql\n");
+        // find the cam_id of all the exposures that we want to queue up.
+        bare_query = pxDataGet("addtool_find_cam_id.sql");
         // inherit dvodb from camRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(camRun.dvodb IS NOT NULL AND previous_dvodb = camRun.dvodb)");
+    }
+    if (!bare_query) {
+        psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
+	psFree(where);
+	return false;
     }
     // Take the bare query and add the dvodb selector
