DATEDIFF With CASE Statement blank

≡放荡痞女 提交于 2020-01-17 03:15:11

问题


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

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

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?

Appreciate the help.


回答1:


Access SQL doesn't know CASE WHEN.

Use the IIf() or Switch() functions instead.



来源:https://stackoverflow.com/questions/36081110/datediff-with-case-statement-blank

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!