Slow Query Filtering on Concatenated Variable (1 Viewer)

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
Howdy, it's been a while, hope everybody's in good spirits.

Have a question. I am trying to use a criteria to filter out nulls in concatenated variable, which slows the query considerably.
Is there a quick workaround?
The part that makes it slow looks like this -
...
WHERE ... AND (([tbl1].[x] & [tbl1].[y]) <> "") AND ...

If I work them individually, it's not a problem, the query is fast, but I have to combine them first in order to produce the correct output.
Greatly appreciate your help, as always.
Thanks,
Len
 

spikepl

Eledittingent Beliped
Local time
Today, 17:11
Joined
Nov 3, 2010
Messages
6,142
but I have to combine them first in order to produce the correct output.

why?

also, you are not filtering out nulls, you are filtering out zero-length strings - a different animal altogether.
 

vbaInet

AWF VIP
Local time
Today, 16:11
Joined
Jan 22, 2010
Messages
26,374
WHERE ... AND (([tbl1].[x] & [tbl1].[y]) <> "") AND ...
And that's why it's slow because you've lost the power of indexing.
 

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
Because I have cases when only one of the variables is null, in which case I'd like to keep the record. But when both are null, I want to drop that record.
I did try to play with ' Is Not Null ' vs ' <>"" ', and functions like Trim() and Len(), but nothing helped.
 

vbaInet

AWF VIP
Local time
Today, 16:11
Joined
Jan 22, 2010
Messages
26,374
Do it separately and change the Allow Zero Length String property of the fields to No.
 

spikepl

Eledittingent Beliped
Local time
Today, 17:11
Joined
Nov 3, 2010
Messages
6,142
Then the condition is:

NOT (VarA Is Null AND VarB Is Null)
 

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
Not sure I can index, I am using Access front (Access 2013), but my tables are on SQL server.. I mean, I can ask 'them' to index variables in the tables on the server I suppose.. can you tell me more please.. thanks.
 

spikepl

Eledittingent Beliped
Local time
Today, 17:11
Joined
Nov 3, 2010
Messages
6,142
I'm too lazy to retype stuff you can easily google yourself. So google or wait for vbaInet.
 

vbaInet

AWF VIP
Local time
Today, 16:11
Joined
Jan 22, 2010
Messages
26,374
Concatenated fields = No Index

Do it as spikepl showed in post #6.
 

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
Yep, #6 did it! Brilliant.. and simple too, as I was hoping.
Thanks much, guys.
L
 

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
and another thanks goes to spikepl for educating me on what San Serriffe is.. fun!
 

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
An old thread, but just wanted to add something for posterity.
I realized I still had issues even with that #6 solution, NOT (VarA Is Null AND VarB Is Null), not in Access itself, but when I was trying to use the query as a data source for a pivot table in Excel.
Somebody suggested this -
[FONT=&quot]...[/FONT][FONT=&quot] ((VarA Is Not Null) OR (VarB Is Not Null)) ...[/FONT]
which seem to fix problems in both Access and Excel.
l
 

spikepl

Eledittingent Beliped
Local time
Today, 17:11
Joined
Nov 3, 2010
Messages
6,142
The two are fully equivalent in logical algebra:

NOT (A AND B) = NOT A OR NOT B

but according to your story Excel does not follow logic :D
 

lemo

Registered User.
Local time
Today, 11:11
Joined
Apr 30, 2008
Messages
187
But it's true!
And the worst thing is I have no idea why. I am relatively good at Excel, less so at Access, and have really no clue what happens when the two communicate with each other.
Access rewrote NOT (VarA Is Null AND VarB Is Null) as ((VarA Is Null And VarB Is Null)=False) maybe that's the problem? When I try refreshing data in Excel, the error message is rather generic "Error Obtaining Data". Whereas before it was more interesting "... incorrect syntax near '='...".
And no errors with NOT A OR NOT B.
l
 

Users who are viewing this thread

Top Bottom