我想写一个脚本使用CASE statemetn来比较两个日期。例如,如果患者在预约日期之后取消预约,则应该在“之后”读取;如果患者在预约日期之前取消,则应在“之前”阅读。我怎样才能做到这一点?SQL CASE语句与日期标准
例(以下没有工作):
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
你有一个名为'AppointmentDateTime'的列吗?如果是,那么你的查询工作所需要的就是从AppointmentDateTime删除单引号(''') – Lamak