Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 带有日期条件的sql CASE语句_Sql Server - Fatal编程技术网

Sql server 带有日期条件的sql CASE语句

Sql server 带有日期条件的sql CASE语句,sql-server,Sql Server,我试图使用一个比较两个日期的CASE statemetn来编写脚本。例如,如果患者在预约日期后取消预约,则应改为“之后”;如果患者在预约日期之前取消预约,则应改为“之前”。我怎样才能做到这一点 下面的示例不起作用: Select PatientName, PatientFirstName, PatientLastName, PatientSSN, Age, Gender, AppointmentDateTime, CancelDateTime, CancelNoShowCode,

我试图使用一个比较两个日期的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 
挑选 PatientName,PatientFirstName,PatientLastName,PatientSN,年龄,性别, AppointmentDateTime、CancelDateTime、CancelNoShowCode、约会状态、, 取消原因、取消备注、地点名称、机构名称、, 部门名称、任命SID, 案例 当CancelDateTime>AppointmentDateTime时,然后是'after' 当CancelDateTime 来自mhvisits2 其中CancelDateTime不为null 按病人姓名订购 您的CASE语句中缺少ELSE条件,并从列名中删除了任何“。

是否有名为AppointmentDateTime”的列?如果有,则查询只需从“AppointmentDateTime”中删除单引号即可