SQL query with 200+ Where criteria is too complex (Access 2013) -
so i've never worked sql before, pretty know playing around access's query designer , looking @ resulting sql code. i'm pretty sure i'm not doing efficiently.
here's skinny:
-i have database called "spc data" has measured data each component on each circuit board build.
-i want write 1 sql query fetch around 500 rows based on combinations of barcodes , component data.
-the query built dynamically in vba macro elsewhere, , looks now:
select * [spc data] ((([spc data].barcode)=1504803581) , (([spc data].[component id]) '*r56')) or ((([spc data].barcode)=1433700392) , (([spc data].[component id]) '*c15')) or ((([spc data].barcode)=1433700664) , (([spc data].[component id]) '*r56')) or ((([spc data].barcode)=1433700486) , (([spc data].[component id]) '*r56')) or ... 220 more lines of criteria
i feel shouldn't memory-intensive, access complains query complex unless pare query down around 60 or'd criteria (might work more, random value worked).
my question this: why won't sql execute? writing sql in way making inefficient , overly complex access? there better way select bunch of matched pairs of criteria? or should split multiple sql queries, ~60 criteria each? i'll grateful direction on this.
update (1 hour later): still don't have robust solution; unions didn't i'm guessing access issue. can try making temporary table of records need , joining original of column data drapp suggested, or split sql , import them 60 @ time. hoping there obvious mistake making.
i don't think suggestion use "in" clause work if barcode can applicable multiple component ids? not sure, possible?
what might better @ getting solution create secondary table , insert things looking for, join that. not exactly, principle as:
create table tmpjoin( trybarcode integer, trycomponent varchar(5)) insert tmpjoin ( trybarcode, trycomponent ) values ( 1504803581, '*r56' ) insert tmpjoin ( trybarcode, trycomponent ) values ( 1433700392, '*c15') insert tmpjoin ( trybarcode, trycomponent ) values ( 1433700664, '*r56') insert tmpjoin ( trybarcode, trycomponent ) values ( 1433700486, '*r56') etc many things looking for...
now, query...
select sd.* [spc data] sd join tmpjoin on sd.barcode = tmpjoin.trybarcode , sd.[component id] tmpjoin.trycomponent
so, if have 1 or 1000 entries in tmpjoin, query doesn't longer. finds match or doesn't , returns row spc data table
of course, need have index on tmpjoin table query optimization, , either delete/recreate during each search or create new random table name , delete when done if multiple people running query, not cause conflict... other options adding column identify unique new person's query , deleting records when finished running query.
Comments
Post a Comment