두 날짜를 비교하는 CASE statemetn을 사용하여 스크립트에 쓰려고합니다. 예를 들어, 약속 날짜 이후에 환자가 약속을 취소하면 '이후'를 읽어야합니다. 환자가 약속 날짜 이전에 취소하면 'before'라고 읽어야합니다. 이것을 어떻게 할 수 있습니까?날짜 조건이 포함 된 사례 코드
예 (아래 작동하지 않았다) :
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