|
|
Subject:
Microsoft Access - Find function; want code to make a mass query
Category: Computers > Programming Asked by: wolvies-ga List Price: $10.00 |
Posted:
08 Jan 2003 04:27 PST
Expires: 07 Feb 2003 04:27 PST Question ID: 139183 |
With the Find function in Microsoft Access, the program will search up and down a field for the value you input as the search string, including leading and trailing spaces. This can be replicated by a simple select query using the same string and the * before and after. eg if searching for the value 'Myint' in a list of names, you would simply set the criteria to *" myint "* the spaces indicating you want the word as a discreet whole and not part of another (eg myinting) I want to write a query which compares a list of surnames on the one hand (a couple of hundred) with a list of full names, formatted in many different ways on the other hand (around half a million) Normal queries running two tables against each other would compare the entire value of the field, and not look for the surname matches like the Find function, or the one by one query. Obviously I could run a couple of hundred separate queries to do this, but assume that there is code that can be used to in effect generate a mass query checking whether the surnames appear anywhere in the the list of half a million full names. If unsure of what I mean please ask for clarification | |
| |
|
|
Subject:
Re: Microsoft Access - Find function; want code to make a mass query
Answered By: mathtalk-ga on 08 Jan 2003 09:43 PST Rated: |
Hi, wolvies-ga: Assume you have a Person table, with a text field called FullName. This is the table that contains half a million records to be searched in your description. Let's also assume the couple of hundred surnames are listed in another table, called say Surname, with just a single text field "MyText". Here is a query that returns the subset of records in the Person table whose FullName field contains any of the Surname.MyText values as substrings: SELECT * FROM Person WHERE EXISTS (SELECT * FROM Surname WHERE Person.FullName Like "*"&Surname.MyText&"*") Note that Access's Like requires matching case in the specified patterns. Since the capitalization of names is sometimes variable, you might want to make the query a little more robust by using the LCase( ) function, which converts strings to all lowercase. Thus: SELECT * FROM Person WHERE EXISTS (SELECT * FROM Surname WHERE LCase(Person.FullName) Like "*"&LCase(Surname.MyText)&"*") Notice that after the EXISTS keyword in both queries, there follows a "subquery" in parentheses which "depends" on the Person.FullName field defined by the "outer" main query. What the "EXISTS" keyword in SQL does results in a "true" value if there are one or more records returned by the "dependent subquery, or in a "false" value if there are no such records. In these sample statements the dependent subquery is designed to test whether the FullName field given in the outer query contains any of the possible matching surname strings. regards, mathtalk-ga | |
| |
| |
|
wolvies-ga
rated this answer:
Thank you |
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |