Notification

Icon
Error

Limit report to only include last logon time - Need help eliminating multiple entries in report

Posted: Friday, November 1, 2019 5:40:08 PM(UTC)
GMFDE

GMFDE

Member Alpha Tester Original PosterPosts: 47
0
Like
I have a report that lists the systems that have not logged on in the last 30 days. I need to find a way to limit this to show just the last log on event. Below is what I have so far. Any help would be appreciated.

Code:
Select Distinct Top 1000000 tblAssets.AssetID,
  tblAssets.AssetName,
  tblAssets.Username,
  tsysAssetTypes.AssetTypename,
  tsysAssetTypes.AssetTypeIcon10 As icon,
  tblAssets.IPAddress,
  tblAssets.Lastseen,
  tblAssets.Lasttried,
  tblCPlogoninfo.logontime
From tblAssets
  Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
  Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
  Inner Join tblCPlogoninfo On tblAssets.AssetID = tblCPlogoninfo.AssetID
  Inner Join tblADComputers On tblAssets.AssetID = tblADComputers.AssetID
  Inner Join (Select tblCPlogoninfo.AssetID,
        tblCPlogoninfo.Username,
        tblCPlogoninfo.Domain,
        Max(tblCPlogoninfo.logontime) As LastLogonTime
      From tblCPlogoninfo
      Group By tblCPlogoninfo.AssetID,
        tblCPlogoninfo.Username,
        tblCPlogoninfo.Domain) T1 On T1.AssetID = tblAssets.AssetID
Where tblCPlogoninfo.logontime Is Not Null And tblCPlogoninfo.logontime <
  GetDate() - 30 And tblAssetCustom.State = 1 And
  tblADComputers.OU Like '%citrix%'
GMFDE
#1GMFDE Member Alpha Tester Original PosterPosts: 47  
posted: 11/25/2019 8:34:11 PM(UTC)
bump
Originally Posted by: GMFDE Go to Quoted Post
I have a report that lists the systems that have not logged on in the last 30 days. I need to find a way to limit this to show just the last log on event. Below is what I have so far. Any help would be appreciated.

Code:
Select Distinct Top 1000000 tblAssets.AssetID,
  tblAssets.AssetName,
  tblAssets.Username,
  tsysAssetTypes.AssetTypename,
  tsysAssetTypes.AssetTypeIcon10 As icon,
  tblAssets.IPAddress,
  tblAssets.Lastseen,
  tblAssets.Lasttried,
  tblCPlogoninfo.logontime
From tblAssets
  Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
  Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
  Inner Join tblCPlogoninfo On tblAssets.AssetID = tblCPlogoninfo.AssetID
  Inner Join tblADComputers On tblAssets.AssetID = tblADComputers.AssetID
  Inner Join (Select tblCPlogoninfo.AssetID,
        tblCPlogoninfo.Username,
        tblCPlogoninfo.Domain,
        Max(tblCPlogoninfo.logontime) As LastLogonTime
      From tblCPlogoninfo
      Group By tblCPlogoninfo.AssetID,
        tblCPlogoninfo.Username,
        tblCPlogoninfo.Domain) T1 On T1.AssetID = tblAssets.AssetID
Where tblCPlogoninfo.logontime Is Not Null And tblCPlogoninfo.logontime <
  GetDate() - 30 And tblAssetCustom.State = 1 And
  tblADComputers.OU Like '%citrix%'


Esben.D
#2Esben.D Member Administration Posts: 1,956  
posted: 11/26/2019 11:11:14 AM(UTC)
What if you remove the time constraint in the where clause and use the MAX in your select for tblCPlogoninfo.logontime?

I believe that should work.

https://www.w3schools.co...l/func_sqlserver_max.asp

Active Discussions

Lansweeper iManage Client deployment
by  CyberCitizen   Go to last post Go to first unread
Last post: Today at 3:09:47 AM(UTC)
Lansweeper Missing hyperv host details for guest asset LAN-4130
by  danielm  
Go to last post Go to first unread
Last post: 12/7/2019 7:15:56 AM(UTC)
Lansweeper Lansweeper showing MAC address instead of name
by  crashff   Go to last post Go to first unread
Last post: 12/6/2019 10:26:25 PM(UTC)
Lansweeper Dell Warranty Lookup - Incorrect Information
by  Trenton Knew  
Go to last post Go to first unread
Last post: 12/6/2019 10:17:15 PM(UTC)
Lansweeper Incoming Email Parse
by  UEFT   Go to last post Go to first unread
Last post: 12/6/2019 5:46:22 PM(UTC)
Lansweeper SSH - Keyboard Interactive Authentication
by  KevinA-REJIS  
Go to last post Go to first unread
Last post: 12/6/2019 5:22:21 PM(UTC)
Lansweeper Custom OID Scanning / multible OIDs with wildcards
by  Esben.D  
Go to last post Go to first unread
Last post: 12/6/2019 11:57:18 AM(UTC)