2 つの日付を比較する CASE ステートメントを使用してスクリプトに書き込もうとしています。たとえば、患者が予約日の後に予約をキャンセルした場合は、'after' と読む必要があります。患者が予約日の前にキャンセルした場合は、「前」と読む必要があります。どうすればこれを達成できますか?
例 (以下は機能しませんでした):
Select
PatientName, PatientFirstName, PatientLastName, PatientSSN, Age, Gender,
AppointmentDateTime, CancelDateTime, CancelNoShowCode, Appointment_Status,
CancellationReason, CancellationRemarks, LocationName, InstitutionName,
DivisionName, AppointmentSID,
CASE WHEN CancelDateTime > 'AppointmentDateTime' then 'after'
WHEN CancelDateTime < 'AppointmentDateTime' then 'BEFORE'
END as WHENCANCELLED
from #mhvisits2
where CancelDateTime is NOT null
order by PatientName