Index: trunk/ippTools/src/detselect.c
===================================================================
--- trunk/ippTools/src/detselect.c	(revision 9394)
+++ trunk/ippTools/src/detselect.c	(revision 9395)
@@ -160,5 +160,5 @@
 
     if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detNormalizedImfile");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
Index: trunk/ippTools/src/detselectConfig.c
===================================================================
--- trunk/ippTools/src/detselectConfig.c	(revision 9394)
+++ trunk/ippTools/src/detselectConfig.c	(revision 9395)
@@ -136,8 +136,45 @@
     } \
 }
+#define addWhereS32(name) \
+{ \
+    psS32 s32 = 0; \
+    bool status = false; \
+    if ((s32= psMetadataLookupS32(&status, config->args, "-" #name))) { \
+        if (!psMetadataAddS32(config->where, PS_LIST_TAIL, #name, 0, "==", s32)) { \
+            psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \
+            goto FAIL; \
+        } \
+    } \
+}
+
+#define addWhereF32(name) \
+{ \
+    psF32 var = 0; \
+    bool status = false; \
+    if (!isnan(psMetadataLookupF32(&status, config->args, "-" #name))) { \
+        if (!psMetadataAddF32(config->where, PS_LIST_TAIL, #name, 0, "==", var)) { \
+            psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \
+            goto FAIL; \
+        } \
+    } \
+}
+
+#define addWhereF64(name) \
+{ \
+    psF64 var = 0; \
+    bool status = false; \
+    if (!isnan(psMetadataLookupF64(&status, config->args, "-" #name))) { \
+        if (!psMetadataAddF64(config->where, PS_LIST_TAIL, #name, 0, "==", var)) { \
+            psError(PS_ERR_UNKNOWN, false, "failed to add item " #name); \
+            goto FAIL; \
+        } \
+    } \
+}
 
     // generate SQL where clause
     config->where = psMetadataAlloc();
 
+    addWhereStr(det_id);
+    addWhereS32(iteration);
     addWhereStr(exp_tag);
     // convert '-inst' to 'camera'
@@ -154,17 +191,12 @@
     addWhereStr(telescope);
     addWhereStr(exp_type);
-    {
-        int imfiles = 0; 
-        bool status = false;
-        if ((imfiles = psMetadataLookupS32(&status, config->args, "-imfiles"))) {
-            if (!psMetadataAddS32(config->where, PS_LIST_TAIL, "imfiles", 0, "==", imfiles)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item imfiles");
-                goto FAIL;
-            }
-        }
-    }
+    addWhereStr(det_type);
+    addWhereS32(imfiles);
     addWhereStr(class);
     addWhereStr(class_id);
     addWhereStr(filter);
+    addWhereF32(exp_time);
+    addWhereF64(ccd_temp);
+    addWhereF32(airmass);
 
     if (config->where->list->n < 1) {
