Hello,
I'm try to use a execute a query from a form to show all duplicate patients in my database. I have the basic code to get it to work, however due to the nature of our patients we sometimes get reversal of first and last name, they will get tested multiple times over the course of their treatment and sometimes they give their names differently and I would like to also include this possibility of firstname=surname AND surname=firstname but I'm not sure how to do this.
eg. The first time they come in to be tested they give the name Harvey George, and the next time they may give George Harvey. (To complicate things further we don't always get DOB and Healthcard number)
Here's the code I'm currently using:
SELECT ENTRYTABLE.FirstName, ENTRYTABLE.Surname, ENTRYTABLE.DOB, ENTRYTABLE.HEALTHCARD_No, ENTRYTABLE.RECDATE, ENTRYTABLE.PatientAddress
FROM ENTRYTABLE
WHERE (((ENTRYTABLE.FirstName) In (SELECT [FirstName] FROM [ENTRYTABLE] As Tmp GROUP BY [FirstName],[Surname],[DOB],[HEALTHCARD_No] HAVING Count(*)>1 And [Surname] = [ENTRYTABLE].[Surname] And ( [DOB] = [ENTRYTABLE].[DOB] or [HEALTHCARD_No] = [ENTRYTABLE].[HEALTHCARD_No]))))
ORDER BY ENTRYTABLE.FirstName, ENTRYTABLE.Surname, ENTRYTABLE.DOB, ENTRYTABLE.HEALTHCARD_No,ENTRYTABLE.RECDATE;
I'm try to use a execute a query from a form to show all duplicate patients in my database. I have the basic code to get it to work, however due to the nature of our patients we sometimes get reversal of first and last name, they will get tested multiple times over the course of their treatment and sometimes they give their names differently and I would like to also include this possibility of firstname=surname AND surname=firstname but I'm not sure how to do this.
eg. The first time they come in to be tested they give the name Harvey George, and the next time they may give George Harvey. (To complicate things further we don't always get DOB and Healthcard number)
Here's the code I'm currently using:
SELECT ENTRYTABLE.FirstName, ENTRYTABLE.Surname, ENTRYTABLE.DOB, ENTRYTABLE.HEALTHCARD_No, ENTRYTABLE.RECDATE, ENTRYTABLE.PatientAddress
FROM ENTRYTABLE
WHERE (((ENTRYTABLE.FirstName) In (SELECT [FirstName] FROM [ENTRYTABLE] As Tmp GROUP BY [FirstName],[Surname],[DOB],[HEALTHCARD_No] HAVING Count(*)>1 And [Surname] = [ENTRYTABLE].[Surname] And ( [DOB] = [ENTRYTABLE].[DOB] or [HEALTHCARD_No] = [ENTRYTABLE].[HEALTHCARD_No]))))
ORDER BY ENTRYTABLE.FirstName, ENTRYTABLE.Surname, ENTRYTABLE.DOB, ENTRYTABLE.HEALTHCARD_No,ENTRYTABLE.RECDATE;