Find records in which field 1 contains parts of field 2

P

Puzzle Lover

Hello,

In a Select Query, I need to retrieve all record in which [Code String]
contains [Codes]. Example:

[Code String] [Codes]
Record 1: "AA4 AB1 B5O CD2 EF3" "AA4 CD2" --->Retrieve Record 1
Record 2: "A14 AB1 B5O CD2 EF3" "AA4 CD2" --->Do not Retrieve
Record 2

Is this possible? Could I write the [Codes] content using AND and OR?

Thank you!
 
J

Jerry Whittle

If, big IF, there are always two codes in the Codes fields seperated by a
space, the following should work once you put in the proper table and field
names. Watch out for word wrapping:

SELECT tblCodes.*
FROM tblCodes
WHERE (((tblCodes.[Code String]) Like "*" &
Trim(Left([Codes],InStr([Codes]," "))) & "*")
AND ((tblCodes.[Code String]) Like "*" & Trim(Mid([Codes],InStr([Codes],"
"))) & "*"));

If at all possible, get your data properly normalized. Having multiple
'things' in a field can cause all kinds of problems as you can see.
 
R

Rap

Once you separate the parts, you should be able to figure it out. Use this
to separate them:

SELECT Mid([Code String],1,3) AS Part1,Mid([Code String],5,3) AS
Part2,Mid([Code String],9,3) AS Part3,Mid([Code String],13,3) AS Part4,
Mid([Code String],17,3) AS Part5
FROM Table1;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top