One table of data has been extracted from a live read-only database via odbc.
I wish to add a new field to each record based on the combination of two other fields - Nom and Dept below
I'm trying to use a query with no joins and the query returns a new line for each output from my iif clause.
NewField Nom Nom2 Nom3 Nom4 Nom5 NomFr NomTo NomFr2 NomTo2 NomFr3 NomTo3 Dept Dept2 Dept3 DeptFr DeptTo DeptFr2 DeptTo2 DeptFr3 DeptTo3 DeptFr4 DeptTo4 Name 1 7000 7006 101 229 250 274 276 289 291 299 Name 2 5009 5055 7300 7400 8001 8251 7808 7809 700 Name 3 7100 2300 2331 7000 7006 0 500 Name 4 4001 4400 202 49 701 1 8 Name 5 4420 29 Name 6 4400 5071 5055 572 Name 7 4400 4020 4010 4011 701 300 399
NewField: iif(table.nom = nom.nom or table.nom =nom2.nom2 or table.nom =nom3.nom3 or table.nom =nom4.nom4 or table.nom between nomfr.nomfr and nomto.nomto or table.nom between nomfr2.nomfr2 and nomto2.nomto2 or table.nom between nomfr3.nomfr3 and nomto3.nomto3,iif(table.dept = dept.dept or table.dept = dept2.dept2 or table.dept between deptfr.deptfr and deptto.deptto or table.dept between deptfr2.deptfr2 and deptto2.deptto2 or table.dept between deptfr3.deptfr3 and deptto3.deptto3 or table.dept between deptfr4.deptfr4 and deptto4.deptto4,data.newfield))
There must be a better way- this takes 4 minutes and returns duplicate lines - this stops me searching for null values so that I can identify gaps in the complicated field mapping.
There are 10,000,000 max combinations but only about 5,000 in use.
How should I plan this query?