Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query with Like "*[fieldName]"

Status
Not open for further replies.

rjmccafferty

IS-IT--Management
Jul 16, 2001
29
US
I am trying to design a query in which I have a list of Names in a table (first and last names combined, e.g. John Smith) indicating the recipients of a book, and I want to limit the results of the query to those of individuals with the same last name who work for the same company.

That is, is Company A had books sent to John Smith and Harold Adams, I want to see which contacts at the same company have the last name of Smith or Adams.

I first linked the two tables by CompanyID and set the union to All records in the first table above with only those matching records in the second table above. Thus I am trying to see all matches for those people listed as receiving a book, but have no interest in those who did not receive a book.

The resulting SQL statement is:
SELECT PPM_History.PPM_Recipient, [contact].[fname] & " " & [contact].[lname] AS name, Contact.LName
FROM PPM_History LEFT JOIN Contact ON PPM_History.CustomerID = Contact.CustomerID
WHERE (((PPM_History.PPM_Recipient) Like "*[contact].[lname]*"));

When I run the query, I get no hits when, in fact, I know there are many matches. If I remove the WHERE statement I get a row for every individual in each related company.

Ultimately, I am trying to find book recipients whose names may not be exactly correct in the table and am just trying to see all last name matches so I can visually check first names to see if they are accurate.

What am I doing wrong in my query?
 
Change your criteria to look like this.
LIKE "*" & [contact].[lname] & "*"
That should work for you. The hardest questions always have the easiest answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top