‎02-05-2021 02:34 PM
Select Top 1000000 Case
When LastPatchDate.lastPatchDate >= DateAdd(day, -7, GetDate()) Then
'1. less than a week'
When LastPatchDate.lastPatchDate < DateAdd(day, -7, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -30, GetDate()) Then
'2. less than a month'
When LastPatchDate.lastPatchDate < DateAdd(day, -31, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -90, GetDate()) Then
'3. less than 3 months'
Else '4. more than 3 months'
End As DateRange,
count(*) As NumberOfAssets
From (Select Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
tsysOS.OSname,
tblAssets.Username,
tblAssets.IPAddress,
tblAssets.Description,
Max(Convert(date,tblQuickFixEngineering.InstalledOn)) As lastPatchDate,
tblAssets.Lastseen
From tblQuickFixEngineering
Join tblAssets On tblAssets.AssetID = tblQuickFixEngineering.AssetID
Join tsysOS On tblAssets.OScode = tsysOS.OScode
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Where tblAssetCustom.State = 1
Group By tblAssets.AssetID,
tblAssets.AssetName,
tsysOS.OSname,
tblAssets.Username,
tblAssets.IPAddress,
tblAssets.Description,
tblAssets.Lastseen
Order By lastPatchDate) As LastPatchDate
Group By Case
When LastPatchDate.lastPatchDate >= DateAdd(day, -7, GetDate()) Then
'1. less than a week'
When LastPatchDate.lastPatchDate < DateAdd(day, -7, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -30, GetDate()) Then
'2. less than a month'
When LastPatchDate.lastPatchDate < DateAdd(day, -31, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -90, GetDate()) Then
'3. less than 3 months'
Else '4. more than 3 months'
End
Where tblComputers.OU Like '%OU=Finance%'but i'm not really sure how to go about doing it.
‎02-05-2021 04:43 PM
Select Top 1000000
Case
When LastPatchDate.lastPatchDate >= DateAdd(day, -7, GetDate()) Then '1. less than a week'
When LastPatchDate.lastPatchDate < DateAdd(day, -7, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -30, GetDate()) Then '2. less than a month'
When LastPatchDate.lastPatchDate < DateAdd(day, -31, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -90, GetDate()) Then '3. less than 3 months'
Else '4. more than 3 months'
End As DateRange,
count(*) As NumberOfAssets
From
( Select Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
tsysOS.OSname,
tblAssets.Username,
tblAssets.IPAddress,
tblAssets.Description,
Max(Convert(date,tblQuickFixEngineering.InstalledOn)) As lastPatchDate,
tblAssets.Lastseen
From
tblQuickFixEngineering
Join tblAssets On tblAssets.AssetID = tblQuickFixEngineering.AssetID
Join tsysOS On tblAssets.OScode = tsysOS.OScode
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
-- link in the computer AD info
Inner Join tblADComputers ON tblADComputers.AssetID = tblAssets.AssetID
Where
tblAssetCustom.State = 1
-- filter on the computer AD info
AND tblADComputers.OU LIKE '%OU=Finance%'
Group By
tblAssets.AssetID,
tblAssets.AssetName,
tsysOS.OSname,
tblAssets.Username,
tblAssets.IPAddress,
tblAssets.Description,
tblAssets.Lastseen
Order By
lastPatchDate) As LastPatchDate
Group By
Case
When LastPatchDate.lastPatchDate >= DateAdd(day, -7, GetDate()) Then '1. less than a week'
When LastPatchDate.lastPatchDate < DateAdd(day, -7, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -30, GetDate()) Then '2. less than a month'
When LastPatchDate.lastPatchDate < DateAdd(day, -31, GetDate()) And LastPatchDate.lastPatchDate >= DateAdd(day, -90, GetDate()) Then '3. less than 3 months'
Else '4. more than 3 months'
End
‎02-05-2021 03:56 PM
‎02-05-2021 03:41 PM
...
From
tblQuickFixEngineering
Join tblAssets On tblAssets.AssetID = tblQuickFixEngineering.AssetID
Join tsysOS On tblAssets.OScode = tsysOS.OScode
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tblADComputers ON tblADComputers.AssetID = tblAssets.AssetID
Where
tblAssetCustom.State = 1
AND tblADComputers.OU LIKE '%OU=Finance%'
...
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now