‎07-09-2018 12:26 PM
Select Top 1000000 tblAssets.AssetID,
tblAssets.AssetName,
Coalesce(tsysOS.Image, tsysAssetTypes.AssetTypeIcon10) As icon,
tblCPlogoninfoUser.Domain As Userdomain,
tblCPlogoninfoUser.Username,
tblADusers.Displayname,
tblCPlogoninfoUser.LastLogon,
InstalledViewers.SoftwareNames Viewers,
InstalledOffice.SoftwareNames FullOffice,
tblOperatingsystem.Caption As OS,
tblAssetCustom.Manufacturer,
tblAssetCustom.Model,
(Case
When tsysIPLocations.IPLocation Is Not Null Then tsysIPLocations.IPLocation
Else 'Undefined' End) As IPLocation,
tblADComputers.Description
From tblAssets
Left Join tsysOS On tsysOS.OScode = tblAssets.OScode
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype
Inner Join tblAssetCustom On tblAssetCustom.AssetID = tblAssets.AssetID
Inner Join tblADComputers On tblADComputers.AssetID = tblAssets.AssetID
Inner Join tblOperatingsystem On tblOperatingsystem.AssetID = tblAssets.AssetID
Left Join tsysIPLocations On tblAssets.IPNumeric >= tsysIPLocations.StartIP And tblAssets.IPNumeric <= tsysIPLocations.EndIP
Inner Join (Select [AssetID],
STUFF((
Select ', ' + [softwareName]
From ( Select tblSoftware.AssetID, tblsoftwareuni.softwareName
From tblSoftware
Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblSoftware.softID And (dbo.tblsoftwareuni.softwareName Like 'Microsoft Office%Viewer%' or dbo.tblsoftwareuni.softwareName Like 'Visionneuse Microsoft%')) InstalledViewers
Where (AssetID=InstalledViewersResults.AssetID)
For XML PATH('')),1,2,'') As SoftwareNames
From ( Select tblSoftware.AssetID, tblsoftwareuni.softwareName
From tblSoftware
Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblSoftware.softID And (dbo.tblsoftwareuni.softwareName Like 'Microsoft Office%Viewer%' or dbo.tblsoftwareuni.softwareName Like 'Visionneuse Microsoft%')) InstalledViewersResults
Group By [AssetID]) InstalledViewers On InstalledViewers.AssetID = tblAssets.AssetID
Left Join (Select [AssetID],
STUFF((
Select ', ' + [softwareName]
From ( Select tblSoftware.AssetID, tblsoftwareuni.softwareName
From tblSoftware
Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblSoftware.softID And (dbo.tblsoftwareuni.softwareName Like 'Microsoft Office_Profession%' or dbo.tblsoftwareuni.softwareName Like 'Microsoft Office_Standard%')) InstalledOffice
Where (AssetID=InstalledViewersResults.AssetID)
For XML PATH('')),1,2,'') As SoftwareNames
From ( Select tblSoftware.AssetID, tblsoftwareuni.softwareName
From tblSoftware
Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblSoftware.softID And (dbo.tblsoftwareuni.softwareName Like 'Microsoft Office_Profession%' or dbo.tblsoftwareuni.softwareName Like 'Microsoft Office_Standard%')) InstalledViewersResults
Group By [AssetID]) InstalledOffice On InstalledOffice.AssetID = tblAssets.AssetID Left Join ( select tblCPlogoninfolast.AssetID,
tblCPlogoninfolast.LastLogon,
tblCPlogoninfo.Username,
tblCPlogoninfo.Domain
From (Select AssetID,
Max(logontime) As LastLogon
From tblCPlogoninfo
Group By AssetID) As tblCPlogoninfolast
Inner Join tblCPlogoninfo On tblCPlogoninfo.AssetID = tblCPlogoninfolast.AssetID And tblCPlogoninfo.logontime=tblCPlogoninfolast.LastLogon) As tblCPlogoninfoUser On tblCPlogoninfoUser.AssetID = tblAssets.AssetID
Left Join tblADusers On tblCPlogoninfoUser.Username = tblADusers.Username And tblCPlogoninfoUser.Domain = tblADusers.Userdomain
Where tblAssetCustom.State = 1
Order By tblAssets.AssetName
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now