September 14, 2006 at 9:52 am
September 14, 2006 at 11:08 am
You may try this
SELECT Combined.NursingHomeName, Combined.City, Combined.Street, Combined.State, Combined.ZipCode, Combined.PhoneNumber, Combined.CertifiedNumberOfBeds, Combined.TotalNumberOfResidents, Combined.PercOfOccupiedBeds, Combined.TypeOfOwnerShip, Combined.LocatedWithinAHospital, Combined.MultiNursingHomeOwnerShip
FROM Combined
WHERE Combined.NursingHomeName In
(SELECT [NursingHomeName]
FROM [Combined] As Tmp
WHERE Left([NursingHomeName],5) = Left([Combined].[NursingHomeName],5)
And [City] = [Combined].[City]
GROUP BY Left([NursingHomeName],5),[City]
HAVING Count(*) > 1)
ORDER BY Combined.NursingHomeName, Combined.City;
Ram
September 14, 2006 at 11:19 am
I'm still getting the same error. "You tried to execute a query that does not include the specifed expression 'NursingHomeName' as part of an aggregate function."
I'm guessing that there has to be a simpler and effective way to find duplicates based on a partial match of the first five characters in the NursingHomeName column. But since I have very limited SQL coding ability, I'm completely stuck.
September 14, 2006 at 12:16 pm
Try this.
Select Combined.NursingHomeName, Combined.City, Combined.Street, Combined.State, Combined.ZipCode, Combined.PhoneNumber
from Combined , (
Select Left([NursingHomeName],5) as left5NursingHomeName,[City],Count(*) as Counts
from Combined
group by Left([NursingHomeName],5),[City]
having count(*) > 1 ) Dupe
where Left([Combined.NursingHomeName],5) = left5NursingHomeName and ltrim(rtrim(Combined.City)) = ltrim(rtrim(Dupe.City))
Thanks
Sreejith
September 14, 2006 at 12:33 pm
Thanks for the help! All I had to do was add an ORDER BY statement at the end, and I also made sure that all my columns were selected, instead of just the few you included. I got exactly the results I was looking for.
This is a big breakthrough. I just hope that I'll be able to adapt this same scripting for use with other queries and possibly expanding the matching to include the state as well. As soon as I try to add anything else to the matching or the final ORDER BY statement, I get an error about illegal bracketing for the original Select Left statement. There were a number of cases where there were matching names and cities, but the states were different. Being able to narrow this down to the city AND state matches would save a bit of manual work.
September 15, 2006 at 5:59 pm
Charle,
Are you writting the SQL code yourself? If you use the Design Window for queries, I think you might find this quite a bit easier.
Vic
[font="Comic Sans MS"]Vic[/font]
www.vicrauch.com
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply