I am trying to convert an access query to a stored procedure but am getting an error
ADO error: The sum or average aggregate operation cannot take a bit data type as an argument.
The SQL I am getting the error on is
What I am trying to achieve is to look at appointments and check that for each 'PatientHospitalNo' that they have accepted one appointment (the 'ReferralAppointmentAccepted' field is a tick box - bit data type). If the sum of field 'ReferralAppointmentAccepted' <>1 then I need to show the 'PatientHospitalNo' as they have either not accepted an appointment or have accepted more than 1 appointment.
Can somebody help with how I can 'sum' a bit data type field.
Thanks in advance
Jonathan
ADO error: The sum or average aggregate operation cannot take a bit data type as an argument.
The SQL I am getting the error on is
Code:
SELECT tblPatient.PatientHospitalNo, tblReferral.ReferralID, tblReferral.ReferralIsFastTrackReferral, tblReferral.ReferralCaseCompleted, Sum(tblReferralAppointment.ReferralAppointmentAccepted) AS SumOfReferralAppointmentAccepted
FROM (tblReferral INNER JOIN tblPatient ON tblReferral.ReferralPatientID = tblPatient.PatientID) INNER JOIN tblReferralAppointment ON tblReferral.ReferralID = tblReferralAppointment.ReferralAppointmentReferralID
GROUP BY tblPatient.PatientHospitalNo, tblReferral.ReferralID, tblReferral.ReferralIsFastTrackReferral, tblReferral.ReferralCaseCompleted, tblReferral.ReferralDateOfReferral
HAVING (((tblReferral.ReferralIsFastTrackReferral)=1) AND ((tblReferral.ReferralCaseCompleted) Is Null) AND ((Sum(tblReferralAppointment.ReferralAppointmentAccepted))<>1) AND ((tblReferral.ReferralDateOfReferral)>DATEADD(day, - 45, GETDATE())))
What I am trying to achieve is to look at appointments and check that for each 'PatientHospitalNo' that they have accepted one appointment (the 'ReferralAppointmentAccepted' field is a tick box - bit data type). If the sum of field 'ReferralAppointmentAccepted' <>1 then I need to show the 'PatientHospitalNo' as they have either not accepted an appointment or have accepted more than 1 appointment.
Can somebody help with how I can 'sum' a bit data type field.
Thanks in advance
Jonathan