Sql 当条件输出一个时,需要多个情况

Sql 当条件输出一个时,需要多个情况,sql,expression,case-when,Sql,Expression,Case When,我试图编写一个自定义表达式,说明如果x、y和z都为空,那么getdate从给定日期到今天。这就是我现在所拥有的,但我不确定是否需要为3个字段中的每个字段使用不同的WHEN/THEN语句,或者是否有方法将它们与AND或逗号组合 Case when UnderwritingSuspendedDate is null then datediff(dd,SubmittedToUnderwritingDate,getdate()) when Milestoneapprovedwithconditi

我试图编写一个自定义表达式,说明如果x、y和z都为空,那么getdate从给定日期到今天。这就是我现在所拥有的,但我不确定是否需要为3个字段中的每个字段使用不同的WHEN/THEN语句,或者是否有方法将它们与AND或逗号组合

Case 
 when UnderwritingSuspendedDate is null then datediff(dd,SubmittedToUnderwritingDate,getdate()) 
 when Milestoneapprovedwithconditions is null then datediff(dd,SubmittedToUnderwritingDate,getdate()) 
 when UnderwritingFinalApprovalDate is null then datediff(dd,SubmittedToUnderwritingDate,getdate()) 
END

根据你的逻辑,应该是:

(case when UnderwritingSuspendedDate is null and 
           Milestoneapprovedwithconditions is null and 
           UnderwritingFinalApprovalDate is null 
      then datediff(day, SubmittedToUnderwritingDate, getdate()) 
 end);

请注意,如果这三个值中的任何一个不是
NULL
,则表达式将返回
NULL

示例数据,并且所需的结果将非常有用。太棒了!比我想的要简单得多。感谢您的帮助和快速响应