I have (with the help of this forum) created a query that takes date of birth and puts it in to an age range (the criteria for which is held in a table).
SELECT PD.[Patient SID], PD.[Date of birth], AR.Age_Range
FROM tbl_Patients AS PD, tbl_AgeRange AS AR
WHERE (((DateDiff("d",[PD].[Date of birth],Date())) Between [AR].[Min_Age_Days] And [AR].[Max_Age_Days]));
I also have another query returning 'Active Patients' based on when they joined and when their last appoinment was.
SELECT tbl_Patients.[Patient SID], tbl_Patients.Gender, tbl_Patients.[Total invoiced], tbl_Patients.[Payment plan], tbl_Patients.[Created at], Min(tbl_Appointments.[Start date]) AS [First Appt Date], Max(tbl_Appointments.[Start date]) AS [Last Appt Date], tbl_Patients.[Date of birth], [qry_Age in days and Age Range].Age_Range
FROM [qry_Age in days and Age Range] INNER JOIN (tbl_Patients LEFT JOIN tbl_Appointments ON tbl_Patients.[Patient SID] = tbl_Appointments.[Patient SID]) ON [qry_Age in days and Age Range].[Patient SID] = tbl_Patients.[Patient SID]
WHERE (((tbl_Patients.[Created at])>=44926-1100 And (tbl_Patients.[Created at])<=44926) AND ((tbl_Patients.[Prevent appointment booking])<>-1)) OR (((tbl_Patients.[Prevent appointment booking])<>-1) AND ((tbl_Appointments.[Start date])>=44926-1100 And (tbl_Appointments.[Start date])<=44926))
GROUP BY tbl_Patients.[Patient SID], tbl_Patients.Gender, tbl_Patients.[Total invoiced], tbl_Patients.[Payment plan], tbl_Patients.[Created at], tbl_Patients.[Date of birth], [qry_Age in days and Age Range].Age_Range;
My question is; Is there a way of displaying Age Range in the second query without referring to the first query?
The Age range table is simply set out as this,
SELECT PD.[Patient SID], PD.[Date of birth], AR.Age_Range
FROM tbl_Patients AS PD, tbl_AgeRange AS AR
WHERE (((DateDiff("d",[PD].[Date of birth],Date())) Between [AR].[Min_Age_Days] And [AR].[Max_Age_Days]));
I also have another query returning 'Active Patients' based on when they joined and when their last appoinment was.
SELECT tbl_Patients.[Patient SID], tbl_Patients.Gender, tbl_Patients.[Total invoiced], tbl_Patients.[Payment plan], tbl_Patients.[Created at], Min(tbl_Appointments.[Start date]) AS [First Appt Date], Max(tbl_Appointments.[Start date]) AS [Last Appt Date], tbl_Patients.[Date of birth], [qry_Age in days and Age Range].Age_Range
FROM [qry_Age in days and Age Range] INNER JOIN (tbl_Patients LEFT JOIN tbl_Appointments ON tbl_Patients.[Patient SID] = tbl_Appointments.[Patient SID]) ON [qry_Age in days and Age Range].[Patient SID] = tbl_Patients.[Patient SID]
WHERE (((tbl_Patients.[Created at])>=44926-1100 And (tbl_Patients.[Created at])<=44926) AND ((tbl_Patients.[Prevent appointment booking])<>-1)) OR (((tbl_Patients.[Prevent appointment booking])<>-1) AND ((tbl_Appointments.[Start date])>=44926-1100 And (tbl_Appointments.[Start date])<=44926))
GROUP BY tbl_Patients.[Patient SID], tbl_Patients.Gender, tbl_Patients.[Total invoiced], tbl_Patients.[Payment plan], tbl_Patients.[Created at], tbl_Patients.[Date of birth], [qry_Age in days and Age Range].Age_Range;
My question is; Is there a way of displaying Age Range in the second query without referring to the first query?
The Age range table is simply set out as this,
Min_Age_Days | Max_Age_Days | Age_Range |
---|---|---|
0 | 6570 | <18 |
6570 | 9490 | 18-25 |
9490 | 14965 | 26-40 |
14965 | 20440 | 41-55 |
20440 | 29565 | 56-80 |
29565 | 38325 | 80+ |
44000 | 50000 |