SELECT logcount, logUserID, maxlogtm
, DATEDIFF(day, maxlogtm, GETDATE()) AS daysdiff
FROM statslogsummary
WHERE daysdiff > 120
I get
"invalid column name daysdiff".
Maxlogtm is a datetime field. It's the little stuff that drives me crazy.
SELECT logcount, logUserID, maxlogtm
, DATEDIFF(day, maxlogtm, GETDATE()) AS daysdiff
FROM statslogsummary
WHERE daysdiff > 120
I get
"invalid column name daysdiff".
Maxlogtm is a datetime field. It's the little stuff that drives me crazy.
You could refer to column alias but you need to define it using
CROSS/OUTER APPLY
:DBFiddle Demo
Pros:
WHERE/GROUP BY/ORDER BY