→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !
‎02-18-2015 03:47 PM
Solved! Go to Solution.
‎02-18-2015 06:41 PM
SELECT Distinct Top 1000000
tblAssets.Userdomain,
tblAssets.Username,
LastUserOn.AssetCount
FROM
tblAssets
INNER JOIN tblAssetCustom ON tblAssets.AssetID = tblAssetCustom.AssetID
INNER JOIN tblComputersystem ON tblAssets.AssetID = tblComputersystem.AssetID
INNER JOIN tbldomainroles ON tbldomainroles.Domainrole = tblComputersystem.Domainrole
INNER JOIN tsysOS ON tblAssets.OScode = tsysOS.OScode
LEFT JOIN (SELECT
a.UserDomain,
a.Username,
Count(*) AS AssetCount
FROM
tblAssets AS a
INNER JOIN tblAssetCustom AS c ON a.AssetID = c.AssetID
INNER JOIN tblComputersystem AS s ON a.AssetID = s.AssetID
INNER JOIN tbldomainroles AS r ON r.Domainrole = s.Domainrole
INNER JOIN tsysOS AS o ON a.OScode = o.OScode
WHERE
c.State = 1 -- active asset
AND s.Domainrole < 2 -- not server
AND o.OSname like 'Win%' -- Windows
GROUP BY
a.UserDomain,
a.Username
) AS LastUserOn ON LastUserOn.UserDomain = tblAssets.UserDomain AND LastUserOn.Username = tblAssets.Username
WHERE
tblAssetCustom.State = 1
AND tblComputersystem.Domainrole < 2
AND LastUserOn.AssetCount > 1
ORDER BY
tblAssets.Userdomain,
tblAssets.Username
‎02-18-2015 06:41 PM
SELECT Distinct Top 1000000
tblAssets.Userdomain,
tblAssets.Username,
LastUserOn.AssetCount
FROM
tblAssets
INNER JOIN tblAssetCustom ON tblAssets.AssetID = tblAssetCustom.AssetID
INNER JOIN tblComputersystem ON tblAssets.AssetID = tblComputersystem.AssetID
INNER JOIN tbldomainroles ON tbldomainroles.Domainrole = tblComputersystem.Domainrole
INNER JOIN tsysOS ON tblAssets.OScode = tsysOS.OScode
LEFT JOIN (SELECT
a.UserDomain,
a.Username,
Count(*) AS AssetCount
FROM
tblAssets AS a
INNER JOIN tblAssetCustom AS c ON a.AssetID = c.AssetID
INNER JOIN tblComputersystem AS s ON a.AssetID = s.AssetID
INNER JOIN tbldomainroles AS r ON r.Domainrole = s.Domainrole
INNER JOIN tsysOS AS o ON a.OScode = o.OScode
WHERE
c.State = 1 -- active asset
AND s.Domainrole < 2 -- not server
AND o.OSname like 'Win%' -- Windows
GROUP BY
a.UserDomain,
a.Username
) AS LastUserOn ON LastUserOn.UserDomain = tblAssets.UserDomain AND LastUserOn.Username = tblAssets.Username
WHERE
tblAssetCustom.State = 1
AND tblComputersystem.Domainrole < 2
AND LastUserOn.AssetCount > 1
ORDER BY
tblAssets.Userdomain,
tblAssets.Username
‎02-18-2015 06:39 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now