我对T-SQL还是很陌生,并希望使用isull简化此查询。
case
when datediff(d, appdate, disdate) IS NOT NULL THEN datediff(d, appdate, disdate)
ELSE
Case
when appdate is null THEN datediff(d,update,getdate())
when disdate IS NULL THEN datediff(d,appdate,getdate())
END
END
答案 0 :(得分:1)
没有太多简化,但这应该做同样的事情:
ISNULL(datediff(d, appdate, disdate) ,
CASE WHEN appdate IS NULL THEN datediff(d,update,getdate())
WHEN disdate IS NULL THEN datediff(d,appdate,getdate()) END
)