P
Paul James
I'm trying to build a query that displays all records that have matching
strings in the first four characters of two different fields: AgentName and
StreetAddress. That is, where the first four characters of AgentName are
equal in both records, AND the first four characters of StreetAddress are
equal in both records.
Since the Find Duplicates Query Wizard creates a query that only finds exact
matches, I ran the Wizard and tried replacing those exact matches in the SQL
code created by the Wizard. I tried enclosing AgentName and StreetAddress
with the
Left() function, using 4 as a parameter. However, Access could not run a
query on that modified code and produced the error message saying that the
criteria was not part of an aggregate function.
To produce the exact matches in those two fields, the query wizard inserts
this SQL code as criteria in the AgentName field (in the QBE screen):
In (SELECT [AgentName] FROM [tblAgent] As Tmp GROUP BY
[AgentName],[AgentStreetAddress] HAVING Count(*)>1 And [AgentStreetAddress]
= [tblAgent].[AgentStreetAddress])
The entire SQL code which includes the above criteria is:
SELECT tblAgent.AgentName, tblAgent.AgentStreetAddress, tblAgent.LicenseeID,
tblAgent.AgentID, tblAgent.AgentOwnerLastName,
tblAgent.AgentOwnerFirstName2, tblAgent.AgentCity, tblAgent.AgentCloseDate,
tblAgent.AgentDenyDate, tblAgent.AgentWithdrawnDate
FROM tblAgent
WHERE (((tblAgent.AgentName) In (SELECT [AgentName] FROM [tblAgent] As Tmp
GROUP BY [AgentName],[AgentStreetAddress] HAVING Count(*)>1 And
[AgentStreetAddress] = [tblAgent].[AgentStreetAddress])))
ORDER BY tblAgent.AgentName, tblAgent.AgentStreetAddress;
Can anyone tell me how to modify this code so that instead of just
displaying records that have exact matches in both the AgentName and
AgentStreetAddress fields, the query will display all records that have
matching strings in the first four (left) characters of both those fields?
Thanks in advance,
Paul
strings in the first four characters of two different fields: AgentName and
StreetAddress. That is, where the first four characters of AgentName are
equal in both records, AND the first four characters of StreetAddress are
equal in both records.
Since the Find Duplicates Query Wizard creates a query that only finds exact
matches, I ran the Wizard and tried replacing those exact matches in the SQL
code created by the Wizard. I tried enclosing AgentName and StreetAddress
with the
Left() function, using 4 as a parameter. However, Access could not run a
query on that modified code and produced the error message saying that the
criteria was not part of an aggregate function.
To produce the exact matches in those two fields, the query wizard inserts
this SQL code as criteria in the AgentName field (in the QBE screen):
In (SELECT [AgentName] FROM [tblAgent] As Tmp GROUP BY
[AgentName],[AgentStreetAddress] HAVING Count(*)>1 And [AgentStreetAddress]
= [tblAgent].[AgentStreetAddress])
The entire SQL code which includes the above criteria is:
SELECT tblAgent.AgentName, tblAgent.AgentStreetAddress, tblAgent.LicenseeID,
tblAgent.AgentID, tblAgent.AgentOwnerLastName,
tblAgent.AgentOwnerFirstName2, tblAgent.AgentCity, tblAgent.AgentCloseDate,
tblAgent.AgentDenyDate, tblAgent.AgentWithdrawnDate
FROM tblAgent
WHERE (((tblAgent.AgentName) In (SELECT [AgentName] FROM [tblAgent] As Tmp
GROUP BY [AgentName],[AgentStreetAddress] HAVING Count(*)>1 And
[AgentStreetAddress] = [tblAgent].[AgentStreetAddress])))
ORDER BY tblAgent.AgentName, tblAgent.AgentStreetAddress;
Can anyone tell me how to modify this code so that instead of just
displaying records that have exact matches in both the AgentName and
AgentStreetAddress fields, the query will display all records that have
matching strings in the first four (left) characters of both those fields?
Thanks in advance,
Paul