Based on Hogan's answer, and this MSDN article, I've edited my SQL statement to this (below) but MS Query is still not happy.
SELECT CO.MATERIALS1 AS 'Material',
CO.`SIZES#1` AS 'Size',
CO.`TOOLS#1` AS 'Tool',
IR.`BODY /JAW` AS 'BodyJaw',
IR.PN AS 'PartNo'
FROM {oj `COMBINATIONS$` CO
LEFT OUTER JOIN `'INSERTS REVIEW$'` IR
ON [IR.TOOL LIKE '% ' CO.`TOOLS#1` ' %']
AND [IR.SIZE LIKE '% ' CO.`SIZES#1` ' %']
AND [IR.MATERIAL LIKE '% ' CO.MATERIALS1 ' %']}
The syntax for MS Query seems to be slightly different than standard SQL / T-SQL that I've worked with in the past, and I'm struggling to figure out what it wants.
The query above gives me this error about expecting a join operator:
I tried removing the curly braces { }
and it complains about table oj:
I tried removing the oj
reference and it complains about invalid bracketing:
And in frustration I tried removing all brackets, and that makes it complain about a missing operator syntax error:
Aside from that, I've tried quite a few variations on structure, escape characters, concatenation characters, etc. I feel like I'm just spinning my wheels here with MS Query, and hoping that someone more versed in the nuances of MSQ could point out where I'm going wrong, and help me make it right.
I want to do a left join on the CO table, matching size, tool, and material on the IR table:
Which should yield this result:
Also, I realize this will return a match for "P12" on "P12" and "JP12" which is not really the desired behavior, but I feel I can work that out once I get this basic query working. If need be, I could probably add a leading or trailing "/" to every record in that field, so I can then match on "LIKE '%/'" or something like that.
Below ms query will give you the exact result.I have tried with the sample data and the screen shots are attached.
SELECT CO.TOOL, CO.Material, CO.SIZE, IR.PN , IR.`BODY/JAW`
FROM `G:\test1.xlsx`.`COMBINATIONS$` CO
LEFT JOIN `G:\test1.xlsx`.`'INSERTS REVIEW$'` IR
ON CO.TOOL=IR.TOOL
AND ((IR.MATERIAL Like '%'+CO.Material+'%'))
AND ((IR.SIZE Like '%'+CO.Size+'%'))
Test data is shown in the below screen shots.
Following screen shots contains the ms query and result you want.