问题
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