I have taken over management of an Access 2003 database for a medical clinic. Unfortunately, the person who created the DB didn't know much about databases and threw everything into one HUGE table. So right now I have a table called All Clinic Data with the following fields (and about 40 others): PatientID, First Name, Last Name, Appt Date, OB at Appt, Billing Item #1, Second Appt Date, Reason for Second Appt, OB at Second Appt, Billing Item #2.
I know that this is not the optimal way to arrange the data and a complete overhaul of the DB is planned in the future. However, right now I need to create reports containing only the information for the appointments that occured in a certain date range.
This is the SQL query I am currently using to populate my report but it captures all the appointments for a patient from the table if one of them is in the date range given.
SELECT
Format([Input start date],"mm/dd/yy") & " through " & Format([Input end date],"mm/dd/yy") AS Expr1,
[All Clinic Data].[PatientID], [All Clinic Data].[Last Name],
[All Clinic Data].[First Name], [All Clinic Data].[Appt Date],
[All Clinic Data].[OB at Appt], [All Clinic Data].[Billing Item #1],
[All Clinic Data].[Second Appt Date], [All Clinic Data].[Reason for Second Appt],
[All Clinic Data].[OB at Second Appt], [All Clinic Data].[Billing Item #2]
FROM [All Clinic Data]
WHERE (
(([All Clinic Data].[Appt Date])>[Input start date] And
([All Clinic Data].[Appt Date])<[Input end date])
)
OR
(
(([All Clinic Data].[Second Appt Date])>[Input start date] And
([All Clinic Data].[Second Appt Date])<[Input end date])
)
ORDER BY [All Clinic Data].[Last Name];
Note Input start date & Input end date are parameters entered when the query runs. I have tried using the IIF to remove the excess data but I don't know how to structure the statement so that it shows only the appointment dates and associated data (OB and Billing Item) within the given date range.
Example:
1, Sally, Jones, 1/04/2010, Dr.A, 2/05/2011, Dr. B, Flu
2, Jennifer, Baker, 7/05/2010, Dr.X, 15/05/2011, Dr. B, Checkup
3, Joe, Smith, 20/06/2010, Dr.S,
4, Tina, Turner, 17/05/2010, Dr.X, 15/06/2011, Dr. B, Checkup
If [Input start date] = May 1, 2010 and [Input end date] = May 31, 2010
I'd like my report to contain:
Sally, Jones,
1. 2/05/2011, Dr. B, Flu
Jennifer, Baker,
1. 7/05/2010, Dr.X
2. 15/05/2011, Dr.B, Checkup
Tina, Turner,
1. 17/05/2010, Dr.X
I hope this is enough information. Thank you for your help.
UPDATE 1 Here's my first step towards trying what Mike suggested below. I'm using phn as the identifier for the patient info that I'll grab later. I'm getting an compiliation error and I'm not sophisticated enough to know what I've done wrong. Any ideas?
SELECT
Format([Input start date],"mm/dd/yy") & " through " & Format([Input end date],"mm/dd/yy") AS Expr1,
[All Clinic Data].PHN AS Phn, [All Clinic Data].[Appt Date] AS Date,
[All Clinic Data].[OB at Appt] AS OBName,
[All Clinic Data].[Billing Item #1] AS Billing
FROM [All Clinic Data]
WHERE ([All Clinic Data].[Appt Date]>[Input start date] And [All Clinic Data].[Appt Date]<[Input end date])
UNION
SELECT
Format([Input start date],"mm/dd/yy") & " through " & Format([Input end date],"mm/dd/yy") AS Expr1,
[All Clinic Data].PHN AS Phn, [All Clinic Data].[Second Appt Date] AS Date,
[All Clinic Data].[OB at Second App] AS OBName,
[All Clinic Data].[Billing Item #2] AS Billing FROM [All Clinic Data]
WHERE ([All Clinic Data].[Second Appt Date]>[Input start date] And [All Clinic Data].[Second Appt Date]<[Input end date]);