Use Query to identify certain pattern

mrmmickle1

Well-known Member
Joined
May 11, 2012
Messages
2,461
I need to pull in all records that have a pattern of:

#####a# or #####A#

i.e. 12345a1 or 12345A1

I can't seem to get the syntax right. Can someone help me please?

Code:
[COLOR=#0000ff]SELECT[/COLOR] tblCarrierSummary.[Reference 1]
[COLOR=#0000ff]FROM[/COLOR] tblCarrierSummary
[COLOR=#0000ff]WHERE [/COLOR]((tblCarrierSummary.[Reference 1]) [COLOR=#0000ff]LIKE[/COLOR] #####A#);

Thanks :)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
What if you try this

SELECT tblCarrierSummary.[Reference 1]
FROM tblCarrierSummary
WHERE (((tblCarrierSummary.[Reference 1]) Like "*A*" Or (tblCarrierSummary.[Reference 1]) Like "*a*"));
 
Upvote 0
That won't work because that will include all text that happens to have "a" in the string... I need the pattern Number, Number, Number, Number, Number, (a or A), Number

Thanks for taking a look!
 
Last edited:
Upvote 0
I think I have it working,

Code:
[COLOR=#0000ff]SELECT[/COLOR] tblCarrierSummary.[Reference 1]
[COLOR=#0000ff]FROM[/COLOR] tblCarrierSummary
[COLOR=#0000ff]WHERE[/COLOR] (tblCarrierSummary.[Reference 1])Like "#####a#";

Really odd because I swear I tried this before and it returned 0 records....hmmmm

Seems to work now. Maybe my punctuation was off..

Must have been a PEBCAK (Problem Exists Between Computer And Keyboard) issue...
 
Last edited:
Upvote 0
I was going to also suggest the following, but well done you have found a solution:

What if you use a helper column to show the 6th character then add your criteria based on that character.

SELECT tblCarrierSummary.[Reference 1], Mid([Reference 1],6,1) AS Expr1
FROM tblCarrierSummary;
 
Upvote 0
I need to pull in all records that have a pattern of:

#####a# or #####A#

i.e. 12345a1 or 12345A1

I can't seem to get the syntax right. Can someone help me please?

Code:
[COLOR=#0000ff]SELECT[/COLOR] tblCarrierSummary.[Reference 1]
[COLOR=#0000ff]FROM[/COLOR] tblCarrierSummary
[COLOR=#0000ff]WHERE [/COLOR]((tblCarrierSummary.[Reference 1]) [COLOR=#0000ff]LIKE[/COLOR] #####A#);

Thanks :)
"#####A#"
 
Upvote 0

Forum statistics

Threads
1,221,834
Messages
6,162,268
Members
451,758
Latest member
lmcquade91

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