MS Access - Join 2 Table Where field1 Like 'field2%'

    I have a small table I am trying to join with a large table, and the smaller table [table1] has has a field [field1] containing doc numbers such as "BPI-1111"; however the larger table [table2] has doc numbers in [field2] that start like [field1] but have training characters that always start with a space "BPI-1111 (787N4-1111)".  I need to join these two tables by these fields.
     I know that there would normally be a % after the text in the second part of the like statement, but I'm not sure how to or if it is even possible to use the % variable with a field.  I know that I'm misusing the % sign below, but I don't know where else to put it.  Can someone help me with the like statement or tell me what I should do differently?  Thanks,

I need this ASAP, so thank you in advance for your help...
SELECT [table2].[field3]
FROM [table2] INNER JOIN [table2] ON [table1].[field1] = [table2].[field2]
WHERE ((([table2].[field2]) Like '[table1].[field1]%' ));

Open in new window

Jon BredensteinerProject ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ashish PatelCommented:
Try this.

SELECT [table2].[field3]
FROM [table2] INNER JOIN [table2] ON [table1].[field1] = [table2].[field2]
WHERE [table2].[field2] Like ([table1].[field1] & "%");
You don't use a join but use the where condition to link the records, also this is Access so the wild character it a * not a %

SELECT [table2].[field3]
FROM [table2]
WHERE [table2].[field2] Like '*[table1].[field1]*'

Thinking about it the join may work

SELECT [table2].[field3]
FROM [table2] INNER JOIN [table2] ON [table2].[field2] Like '*[table1].[field1]*'

But I am not sure

Cheers, Andrew

Gustav BrockCIOCommented:
You could combine the above suggestions:

    [table2].[field2] Like [table1].[field1] & '*'


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jon BredensteinerProject ManagerAuthor Commented:
asvforce: your code produced: "Syntax error on JOIN operation" and highlighted [table1]

TextReport: your first suggestion returned 0 records
                    your second suggestion produced: "Syntax error on JOIN operation" and highlighted [table2].[field2] Like '*[table1].[field1]*'

cactus_data: your code worked perfectly for me.

Thank you all for your help
Jon BredensteinerProject ManagerAuthor Commented:
I'll give you guys a little while before I award the points, since asvforce and TextReport were the first to respond to my question, but cactus_data's code actually worked the best.  Thanks again, Jon
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.