-2

我正在尝试使用比较两个日期的 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 
4

1 回答 1

0

选择
PatientName、PatientFirstName、PatientLastName、PatientSSN、Age、Gender、AppointmentDateTime、CancelDateTime、CancelNoShowCode、Appointment_Status、CancellationReason、CancellationRemarks、LocationName、InstitutionName、DivisionName、 AppointmentSID 、
CASE ELSE '' END 为 WHENCANCELLED



from #mhvisits2
where CancelDateTime is NOT null order by PatientName

您在 CASE 语句中缺少 ELSE 条件,并从列名中删除任何 (')。

于 2013-10-02T21:19:52.433 回答