I have an Access 2010 query with a set of criteria like this.
Code A
———-
WHERE Field1 = null AND Field2 = 1 AND Field3 > 0 AND Field4 Between 1 And 2 AND Field5 1234 AND Field 5 5678
AND
(
(Field6 = 1 AND Field7 Not In SELECT[Test]FROM[Query2])
OR
(Field6 = 2 AND Field8 Not In SELECT[Test]FROM[Query2])
)
———-
I normally draft queries using Design view, so because of the OR between the last two criteria, I had to use two rows, with the first six criteria duplicated in both rows, like this.
Code B
———-
Row 1: WHERE Field1 = null AND Field2 = 1 AND Field3 > 0 AND Field4 Between 1 And 2 AND Field5 1234 AND Field 5 5678
AND Field6 = 1 AND Field7 Not In SELECT[Test]FROM[Query2]
Row 2: WHERE Field1 = null AND Field2 = 1 AND Field3 > 0 AND Field4 Between 1 And 2 AND Field5 1234 AND Field 5 5678
AND Field6 = 2 AND Field8 Not In SELECT[Test]FROM[Query2]
———-
The query worked OK but took several minutes to run, so in SQL view, I tried replacing the WHERE statement that Access had generated (i.e., as in Code B, with the first six criteria duplicated for Fields 1-5) with the condensed version (i.e., as in Code A, without those criteria duplicated), and it only took a few seconds to run.
However, if I enter and save the condensed version in SQL view, then the entered version without the duplication is saved, but if I save after changing to Design view, then Access regenerates its own version with the duplication, and it runs slow again. Is this normal, and why the big difference in execution time?