DATEDIFF,CASE语句为空 [英] DATEDIFF With CASE Statement blank
问题描述
我正在SQL查询中提取一些数据,如下所示输出到PHP.
I'm pulling some data in an SQL query to output to PHP as below.
, DATEDIFF('d',Activity.CreatedOn, NOW()) As Dif
, DATEDIFF('d',qSWxSRLastUpdated.MaxOfCreatedOn, NOW()) As LastUpd
, FORMAT((qSWxSRLastUpdated.MaxOfCreatedOn), 'DD-MMM-YYYY') AS Start
, FORMAT((Activity.CreatedOn), 'DD-MMM-YYYY') AS CreatedOn
, DATEDIFF('d',(Select CASE WHEN Activity.CreatedOn > qSWxSRLastUpdated.MaxOfCreatedOn
THEN Activity.CreatedOn
ELSE qSWxSRLastUpdated.MaxOfCreatedOn
END), NOW()) AS MostRecentDate
现在,最初的DATEDIFF语句将日期更新为格式为CreatedOn的最后一个更新与日期格式为Dif的最后一个活动之间的日期差.在我尝试如上所述添加DATEDIFF Case语句之前,所有这些方法都可以正常工作
Now the initial DATEDIFF statements are pulling differences in date between a last update formatted as CreatedOn and a last activity formatted as Dif. These all work fine until I try adding the DATEDIFF Case statement as above
这可能是我对SQL的理解(相对较新),但是查询返回空白到前端,但是没有出错,所以我假设我的代码有问题吗?
It might be my understanding of SQL (being relatively new to it) but the query return blank to the front end but doesn't error out so I'm assuming there's an issue with my code?
感谢帮助.
推荐答案
Access SQL不知道CASE WHEN
.
Access SQL doesn't know CASE WHEN
.
Use the IIf()
or Switch()
functions instead.
这篇关于DATEDIFF,CASE语句为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!