I am trying to track user data for when users log in to an application. What I am trying to pull from my query (below) is all users who have not logged in for the past 30 days or more. However, it is pulling in users who have logged in quite recently. Help?
SELECT UserNM AS [UserID], MAX(EventDT) AS [Last Log-in Date]
FROM dbo.USREventLog
WHERE ABS(DATEDIFF([day], EventDT, GETDATE())) > 30
AND (UserNM NOT LIKE 'user1') AND (UserNM NOT LIKE 'user2')
AND (UserNM NOT LIKE 'user3') AND (UserNM NOT LIKE 'user4')
GROUP BY UserNM
BTW, I am using their most recent record of activity as their last log in date and I have a small list of users who should absolutely not be included in the results.
Try this:
SELECT UserNM AS [UserID], MAX(EventDT) AS [Last Log-in Date]
FROM dbo.USREventLog
WHERE EventDT < GETDATE() - 30
AND (UserNM NOT LIKE 'user1') AND (UserNM NOT LIKE 'user2')
AND (UserNM NOT LIKE 'user3') AND (UserNM NOT LIKE 'user4')
GROUP BY UserNM, EventDT