Good afternoon, I have a query that will tell me if patients are likely to breach their 2-week-wait target and can be brought forward. This is fine. Now what I would like to do is to have another query that will have the same output and basic criteria, i.e. are going to breach, but only to select those who aren't in the first query Qry_2wwBreachAvoidance_20170309.
This is the SQL from the second query
So what I want to achieve is the equivalent of adding this within the WHERE clause:
Without having to include all the code from the first query. Is this possible?
Many thanks,
D€$
This is the SQL from the second query
Code:
SELECT IIf(IsNull([dbo_tblMAIN_REFERRALS].[N2_9_FIRST_SEEN_DATE]),Int(Now()-([N2_6_RECEIPT_DATE]-[N2_14_ADJ_TIME])),[dbo_tblMAIN_REFERRALS].[N2_9_FIRST_SEEN_DATE]-([N2_6_RECEIPT_DATE]-[N2_14_ADJ_TIME])) AS [Estimated 1st Appt Wait], dbo_tblDEMOGRAPHICS.N1_2_HOSPITAL_NUMBER AS MRN, dbo_tblDEMOGRAPHICS.N1_5_SURNAME AS Surname, dbo_tblDEMOGRAPHICS.N1_6_FORENAME AS [Forename(s)], fType([dbo_tblMAIN_REFERRALS]![N2_12_CANCER_TYPE]) AS [Cancer Type], dbo_tblMAIN_REFERRALS.N2_6_RECEIPT_DATE AS [Ref Recd], dbo_tblMAIN_REFERRALS.N2_9_FIRST_SEEN_DATE AS [1st Appointment], [N2_6_RECEIPT_DATE]+14-[N2_14_ADJ_TIME] AS [Save A Breach Date], dbo_tblMAIN_REFERRALS.N2_11_FIRST_SEEN_REASON AS [Breach Reason]
FROM dbo_tblMAIN_REFERRALS INNER JOIN dbo_tblDEMOGRAPHICS ON dbo_tblMAIN_REFERRALS.PATIENT_ID = dbo_tblDEMOGRAPHICS.PATIENT_ID
WHERE (((dbo_tblMAIN_REFERRALS.N2_9_FIRST_SEEN_DATE)>([N2_6_RECEIPT_DATE]+14-[N2_14_ADJ_TIME]) And (dbo_tblMAIN_REFERRALS.N2_9_FIRST_SEEN_DATE)>Now()) AND ((dbo_tblMAIN_REFERRALS.N2_4_PRIORITY_TYPE)="03" Or (dbo_tblMAIN_REFERRALS.N2_4_PRIORITY_TYPE)="02"))
ORDER BY [N2_6_RECEIPT_DATE]+14-[N2_14_ADJ_TIME];
So what I want to achieve is the equivalent of adding this within the WHERE clause:
Code:
And not
(( Qry_2wwBreachAvoidance_20170309.dbo_tblDEMOGRAPHICS.[N1_2_HOSPITAL_NUMBER]) = dbo_tblDEMOGRAPHICS.[N1_2_HOSPITAL_NUMBER]))
Without having to include all the code from the first query. Is this possible?
Many thanks,
D€$