我正在尝试使用比较两个日期的 CASE statemetn 写入脚本。例如,如果患者在预约日期之后取消预约,则应为“之后”;如果患者在预约日期之前取消,则应显示“之前”。我怎样才能做到这一点?
示例(以下不起作用):
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