select sidconf.recordno, sidconf.sid, sdate, edate from sidconf, importdatatype, outer (directtemplate, outer directcustom, outer (groupname, outer gnextra) ) where directoryid is not null and (sidconf.grid is null or (sidconf.grid is not null and length(sidconf.grid) <= 0) ) and sidconf.directoryid = directtemplate.recordno and directtemplate.recordno = directcustom.recordno and directtemplate.extgroupunique = groupname.grid and groupname.grid = gnextra.grid and sidconf.datatype = importdatatype.importdatatypeid and ( (edate IS NULL and sdate <= "30/11/2009") or (edate IS NOT NULL and sdate <= "30/11/2009" and edate >= "01/11/2009") ) UNION select sidconf.recordno, sidconf.sid, sdate, edate from sidconf, importdatatype, outer (groupname, outer gnextra) where sidconf.directoryid is null and (sidconf.grid is not null and length(sidconf.grid) > 0) and sidconf.grid = groupname.grid and sidconf.grid = groupname.grid and groupname.grid = gnextra.grid and sidconf.datatype = importdatatype.importdatatypeid and ( (edate IS NULL and sdate <= "30/11/2009") or (edate IS NOT NULL and sdate <= "30/11/2009" and edate >= "01/11/2009") ) UNION select sidconf.recordno, sidconf.sid, sdate, edate from sidconf, importdatatype, outer (directtemplate, outer directcustom), outer (groupname, outer gnextra) where directoryid is not null and (sidconf.grid is not null and length(sidconf.grid) > 0) and sidconf.directoryid = directtemplate.recordno and directtemplate.recordno = directcustom.recordno and sidconf.grid = groupname.grid and groupname.grid = gnextra.grid and sidconf.datatype = importdatatype.importdatatypeid and ( (edate IS NULL and sdate <= "30/11/2009") or (edate IS NOT NULL and sdate <= "30/11/2009" and edate >= "01/11/2009") ) UNION select sidconf.recordno, sidconf.sid, sdate, edate from sidconf, importdatatype where directoryid is null and (sidconf.grid is null or (sidconf.grid is not null and length(sidconf.grid) <= 0) ) and sidconf.datatype = importdatatype.importdatatypeid and ( (edate IS NULL and sdate <= "30/11/2009") or (edate IS NOT NULL and sdate <= "30/11/2009" and edate >= "01/11/2009") ) order by 1,2,3