Using 'contains' in a query - finding values within strings

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hi Guys,
I want to look at a column and see if it contains 'xyz' or 'abc' anywhere in the string.

I can't work out which access function is used to see if there is a specific value within a string. :confused:

What should I use?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You can use the LIKE function.
The syntax would be something along the lines of

fieldname LIKE "*xyz*"

It also depends if you are using the query designer or straight SQL.
If you are using designer you can just put the LIKE section in the criteria.
 
Upvote 0
Genius!

Although, if you don't mind. Follow up question:
Does the like function look for strings all throughout the value, or just at the start?
 
Last edited:
Upvote 0
If you have the asterisks at either end it will look anywhere in the string.
If you have one just at the end it will look at the beginning of the string and vice versa.

Eg. If you have 3 strings
xyzabc
adcxyz
abxyzc

like "*xyz*" will find all three
like "xyz*" will only find the first one
like "*xyz" will only find the second one
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top