I’ve got a query here which does what it is supposed to but I’m wondering if it is possible to make it more efficient without splitting it into 2 separate queries.
SELECT [Full UO Code] FROM HPP_MD
WHERE LEFT([Full UO Code],5) In
(SELECT IIF([Building]="Site" AND
([Function Name_Usage Type]<>"Property" AND
[Function Name_Usage Type]<>"Undeveloped Land"),[Business Entity],"") As Test
FROM HPP_MD);
This is just a simple Access query that I’m playing with. It is easy to get the results I require if I run the subquery as a ‘create table’ query and then run a second query against that new table to get the required data.
I created the query/subquery out of curiosity to see how it worked but it is pretty slow and I’m wondering if anything can be done to increase efficiency. Is creating a temporary column the correct thing to do here? I couldn’t quite conceive of another way of doing this.
Any thoughts? I know the column headers are pretty atrocious but this was just a quick table I imported into Access and I couldn’t be buggered to change the names in this case.
It looks as if the IN always fails if the big
ANDcomes out false. That’s assuming[Full UO Code]is never the empty string, which may be wrong. But if I’m correct, you can get rid of theIIF, which basically can’t be optimized, into aWHEREIf this is correct so far, you may be able to rewrite the subquery into a self-join. That may or may not be faster. In any case,
[Building]and[Function Name_Usage Type]should be indexed.