Matt, Sure thing! Give this a try:
select
maxuser.userid, maxuser.status, maxuser.pwexpiration
, person.personid, person.displayname
, (select max(attemptdate) from logintracking where logintracking.userid=maxuser.userid and attemptresult='LOGIN' and clienthost like 'EMM_%') as last_attempt
from maxuser
join person on maxuser.personid=person.personid
where
maxuser.status='ACTIVE'
and maxuser.sysuser=0
and not exists (select 1 from logintracking where logintracking.userid=maxuser.userid and attemptresult='LOGIN' and clienthost like 'EMM_%' and attemptdate>getdate()-180)
and exists (select 1 from groupuser where groupuser.userid=maxuser.userid and groupuser.groupname='MAXADMIN')
order by maxuser.userid
;
------------------------------
Tim Ferrill
Solutions Consultant
Intelligent Technology Solutions
tferrill@webuildits.comwww.webuildits.com@tferrill/@webuildits
------------------------------
Original Message:
Sent: Wed June 08, 2022 01:30 PM
From: Matt F
Subject: Query Inactive Users In a Specific Security Group
Hey Tim,
Thanks for the prompt response! This is looking better already. So far so good on my initial checks. I appreciate it!
Is there a way for me to include logintracking.attemptdate to confirm the last login date as well within this same query? Or will I have to compare this with another individual user query check on the logintracking table?
Attempting to join logintracking to this query did not work out so nicely in the results.
------------------------------
Matt F
------------------------------
Original Message:
Sent: Wed June 08, 2022 01:05 PM
From: Tim Ferrill
Subject: Query Inactive Users In a Specific Security Group
Matt,
Does this get you what you want? Obviously you'll need to replace the Group Name in the second Exists statement.
select maxuser.userid, maxuser.status, maxuser.pwexpiration , person.personid, person.displaynamefrom maxuserjoin person on maxuser.personid=person.personidwhere maxuser.status='ACTIVE' and maxuser.sysuser=0 and not exists (select 1 from logintracking where logintracking.userid=maxuser.userid and attemptresult='LOGIN' and clienthost like 'EMM_%' and attemptdate>getdate()-180) and exists (select 1 from groupuser where groupuser.userid=maxuser.userid and groupuser.groupname='MAXADMIN')order by maxuser.userid;
------------------------------
Tim Ferrill
Solutions Consultant
Intelligent Technology Solutions
tferrill@webuildits.com
www.webuildits.com
@tferrill/@webuildits