Select Top 1000000 tblAssets.AssetID, tblAssets.AssetName, tblAssets.Domain, tsysAssetTypes.AssetTypename As AssetType, tblAssets.Username, tblAssets.Userdomain, Coalesce(tsysOS.Image, tsysAssetTypes.AssetTypeIcon10) As icon, tblAssets.IPAddress, Software.softwareName As Software, Software.softwareVersion As Version, Software.SoftwarePublisher As Publisher, tsysIPLocations.IPLocation, tblAssetCustom.Manufacturer, tblAssetCustom.Model, Coalesce(tsysOS.OSname, tblSccmAsset.OsCaption, tblSccmAsset.OperatingSystemNameandVersion) As OS, tblAssets.Version As OSVersion, Case When tblErrors.ErrorText Is Not Null Or tblErrors.ErrorText != '' Then 'Scanning Error: ' + tsysasseterrortypes.ErrorMsg Else '' End As ScanningErrors, tblAssets.Lastseen As [Last successful scan], tblAssets.Lasttried As [Last scan attempt], Case When Software.OutOfDate = 1 Then '#ffadad' Else '#d4f4be' End As backgroundcolor From tblAssets Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID Inner Join tblState On tblState.State = tblAssetCustom.State Left Join (Select tblsoftware.assetid, tblSoftwareUni.softwareName, tblsoftware.softwareVersion, Case When tblSoftwareUni.softwareName Like '%Microsoft Edge' And ((Cast(ParseName(tblsoftware.softwareVersion, 4) As int) < 120) Or (Cast(ParseName(tblsoftware.softwareVersion, 4) As int) = 120 And Cast(ParseName(tblsoftware.softwareVersion, 2) As int) < 2210) Or (Cast(ParseName(tblsoftware.softwareVersion, 4) As int) = 120 And Cast(ParseName(tblsoftware.softwareVersion, 2) As int) = 2210 And Cast(ParseName(tblsoftware.softwareVersion, 1) As int) < 91)) Then 1 Else 0 End As OutOfDate, tblSoftwareUni.SoftwarePublisher From tblsoftware Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblsoftware.softID Where tblSoftwareUni.softwareName Like '%Microsoft Edge' And tblSoftwareUni.SoftwarePublisher Like '%Microsoft Corporation%') As Software On Software.AssetID = tblAssets.AssetID Left Outer Join tsysOS On tsysOS.OScode = tblAssets.OScode Left Outer Join tblSccmAsset On tblAssets.AssetID = tblSccmAsset.AssetId Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID, Max(tblErrors.Teller) As ErrorID From tblErrors Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID = ScanningError.ID Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype = tblErrors.ErrorType Where Software.softwareName Like '%Microsoft Edge' And Software.SoftwarePublisher Like '%Microsoft Corporation%' And tblState.Statename = 'Active' Union Select Top 1000000 tblAssets.AssetID, tblAssets.AssetName, tblAssets.Domain, tsysAssetTypes.AssetTypename As AssetType, tblAssets.Username, tblAssets.Userdomain, tsysAssetTypes.AssetTypeIcon10 As icon, tblAssets.IPAddress, Software.softwareName As Software, Software.Version As Version, Software.SoftwarePublisher As Publisher, tsysIPLocations.IPLocation, tblAssetCustom.Manufacturer, tblAssetCustom.Model, tblMacOSInfo.SystemVersion As OS, tblAssets.Version As OSVersion, Case When tblErrors.ErrorText Is Not Null Or tblErrors.ErrorText != '' Then 'Scanning Error: ' + tsysasseterrortypes.ErrorMsg Else '' End As ScanningErrors, tblAssets.Lastseen As [Last successful scan], tblAssets.Lasttried As [Last scan attempt], Case When Software.OutOfDate = 1 Then '#ffadad' Else '#d4f4be' End As backgroundcolor From tblAssets Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID Inner Join tblState On tblState.State = tblAssetCustom.State Left Join (Select tblMacApplications.assetid, tblSoftwareUni.softwareName, tblMacApplications.Version, Case When tblSoftwareUni.softwareName Like '%Microsoft Edge%' And ((Cast(ParseName(tblMacApplications.Version, 4) As int) < 120) Or (Cast(ParseName(tblMacApplications.Version, 4) As int) = 120 And Cast(ParseName(tblMacApplications.Version, 2) As int) < 2210) Or (Cast(ParseName(tblMacApplications.Version, 4) As int) = 120 And Cast(ParseName(tblMacApplications.Version, 2) As int) = 2210 And Cast(ParseName(tblMacApplications.Version, 1) As int) < 91)) Then 1 Else 0 End As OutOfDate, tblSoftwareUni.SoftwarePublisher From tblMacApplications Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblMacApplications.softid Where tblSoftwareUni.softwareName Like '%Microsoft Edge%') As Software On Software.AssetID = tblAssets.AssetID Inner Join tblMacOSInfo On tblMacOSInfo.AssetID = tblAssets.AssetID Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID, Max(tblErrors.Teller) As ErrorID From tblErrors Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID = ScanningError.ID Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype = tblErrors.ErrorType Where Software.softwareName Like '%Microsoft Edge%' And tblState.Statename = 'Active' Union Select Top 1000000 tblAssets.AssetID, tblAssets.AssetName, tblAssets.Domain, tsysAssetTypes.AssetTypename As AssetType, tblLinuxUser.UserName, tblAssets.Userdomain, tsysAssetTypes.AssetTypeIcon10 As icon, tblAssets.IPAddress, subquery1.Software, subquery1.Version, subquery1.Publisher, tsysIPLocations.IPLocation, tblAssetCustom.Manufacturer, tblAssetCustom.Model, tblLinuxSystem.OSRelease As OS, tblAssets.Version As OSVersion, Case When tblErrors.ErrorText Is Not Null Or tblErrors.ErrorText != '' Then 'Scanning Error: ' + tsysasseterrortypes.ErrorMsg Else '' End As ScanningErrors, tblAssets.Lastseen As [Last successful scan], tblAssets.Lasttried As [Last scan attempt], '#ffadad' As backgroundcolor From tblAssets Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID Inner Join tblState On tblState.State = tblAssetCustom.State Inner Join tblLinuxSystem On tblAssets.AssetID = tblLinuxSystem.AssetID Inner Join tblLinuxUser On tblAssets.AssetID = tblLinuxUser.AssetID Inner Join tblLinuxUserLogon On tblLinuxUserLogon.Id = tblLinuxUser.id Inner Join (Select tblLinuxUser.AssetId, Max(tblLinuxUserLogon.LogonTime) As MaxLogontime From tblLinuxUser Inner Join tblLinuxUserLogon On tblLinuxUserLogon.Id = tblLinuxUser.id Group By tblLinuxUser.assetid) As subquery2 On subquery2.MaxLogontime = tblLinuxUserLogon.LogonTime Inner Join (Select tblSoftwareUni.softwareName As Software, tblSoftwareUni.SoftwarePublisher As Publisher, tblLinuxSoftware.LastChanged, tblLinuxSoftware.assetid, Case When tblLinuxSoftware.Version Like '%-%' Then Left(tblLinuxSoftware.Version, CharIndex('-', tblLinuxSoftware.Version) - 1) When tblLinuxSoftware.Version Like '%R%' Then Left(tblLinuxSoftware.Version, CharIndex('R', tblLinuxSoftware.Version) - 1) Else tblLinuxSoftware.Version End As Version From tblLinuxSoftware Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblLinuxSoftware.SoftwareUniID Where tblSoftwareUni.softwareName = 'microsoft-edge-stable') As subquery1 On subquery1.assetid = tblAssets.assetid Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID, Max(tblErrors.Teller) As ErrorID From tblErrors Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID = ScanningError.ID Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype = tblErrors.ErrorType Where subquery1.Software = 'microsoft-edge-stable' And tblState.Statename = 'Active' And ((Cast(ParseName(subquery1.Version, 4) As int) < 120) Or (Cast(ParseName(subquery1.Version, 4) As int) = 120 And Cast(ParseName(subquery1.Version, 2) As int) < 2210) Or (Cast(ParseName(subquery1.Version, 4) As int) = 120 And Cast(ParseName(subquery1.Version, 2) As int) = 2210 And Cast(ParseName(subquery1.Version, 1) As int) < 91)) Union Select Top 1000000 tblAssets.AssetID, tblAssets.AssetName, tblAssets.Domain, tsysAssetTypes.AssetTypename As AssetType, tblAssets.Username, tblAssets.Userdomain, Coalesce(tsysOS.Image, tsysAssetTypes.AssetTypeIcon10) As icon, tblAssets.IPAddress, Software.softwareName As Software, Software.softwareVersion As Version, Software.SoftwarePublisher As Publisher, tsysIPLocations.IPLocation, tblAssetCustom.Manufacturer, tblAssetCustom.Model, Coalesce(tsysOS.OSname, tblSccmAsset.OsCaption, tblSccmAsset.OperatingSystemNameandVersion) As OS, tblAssets.Version As OSVersion, Case When tblErrors.ErrorText Is Not Null Or tblErrors.ErrorText != '' Then 'Scanning Error: ' + tsysasseterrortypes.ErrorMsg Else '' End As ScanningErrors, tblAssets.Lastseen As [Last successful scan], tblAssets.Lasttried As [Last scan attempt], Case When Software.OutOfDate = 1 Then '#ffadad' Else '#d4f4be' End As backgroundcolor From tblAssets Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID Inner Join tblState On tblState.State = tblAssetCustom.State Left Join (Select tblsoftware.assetid, tblSoftwareUni.softwareName, tblsoftware.softwareVersion, Case When tblSoftwareUni.softwareName Like '%Google Chrome%' And ((Cast(ParseName(tblsoftware.softwareVersion, 4) As int) < 120) Or (Cast(ParseName(tblsoftware.softwareVersion, 4) As int) = 120 And Cast(ParseName(tblsoftware.softwareVersion, 2) As int) < 6099) Or (Cast(ParseName(tblsoftware.softwareVersion, 4) As int) = 120 And Cast(ParseName(tblsoftware.softwareVersion, 2) As int) = 6099 And Cast(ParseName(tblsoftware.softwareVersion, 1) As int) < 129)) Then 1 Else 0 End As OutOfDate, tblSoftwareUni.SoftwarePublisher From tblsoftware Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblsoftware.softID Where tblSoftwareUni.softwareName Like '%Google Chrome%' And tblSoftwareUni.SoftwarePublisher Like '%Google%') As Software On Software.AssetID = tblAssets.AssetID Left Outer Join tsysOS On tsysOS.OScode = tblAssets.OScode Left Outer Join tblSccmAsset On tblAssets.AssetID = tblSccmAsset.AssetId Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID, Max(tblErrors.Teller) As ErrorID From tblErrors Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID = ScanningError.ID Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype = tblErrors.ErrorType Where Software.softwareName Like '%Google Chrome%' And Software.SoftwarePublisher Like '%Google%' And tblState.Statename = 'Active' Union Select Top 1000000 tblAssets.AssetID, tblAssets.AssetName, tblAssets.Domain, tsysAssetTypes.AssetTypename As AssetType, tblAssets.Username, tblAssets.Userdomain, tsysAssetTypes.AssetTypeIcon10 As icon, tblAssets.IPAddress, Software.softwareName As Software, Software.Version As Version, Software.SoftwarePublisher As Publisher, tsysIPLocations.IPLocation, tblAssetCustom.Manufacturer, tblAssetCustom.Model, tblMacOSInfo.SystemVersion As OS, tblAssets.Version As OSVersion, Case When tblErrors.ErrorText Is Not Null Or tblErrors.ErrorText != '' Then 'Scanning Error: ' + tsysasseterrortypes.ErrorMsg Else '' End As ScanningErrors, tblAssets.Lastseen As [Last successful scan], tblAssets.Lasttried As [Last scan attempt], Case When Software.OutOfDate = 1 Then '#ffadad' Else '#d4f4be' End As backgroundcolor From tblAssets Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID Inner Join tblState On tblState.State = tblAssetCustom.State Left Join (Select tblMacApplications.assetid, tblSoftwareUni.softwareName, tblMacApplications.Version, Case When tblSoftwareUni.softwareName Like '%Google Chrome%' And ((Cast(ParseName(tblMacApplications.Version, 4) As int) < 120) Or (Cast(ParseName(tblMacApplications.Version, 4) As int) = 120 And Cast(ParseName(tblMacApplications.Version, 2) As int) < 6099) Or (Cast(ParseName(tblMacApplications.Version, 4) As int) = 120 And Cast(ParseName(tblMacApplications.Version, 2) As int) = 6099 And Cast(ParseName(tblMacApplications.Version, 1) As int) < 129)) Then 1 Else 0 End As OutOfDate, tblSoftwareUni.SoftwarePublisher From tblMacApplications Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblMacApplications.softid Where tblSoftwareUni.softwareName Like '%Google Chrome%') As Software On Software.AssetID = tblAssets.AssetID Inner Join tblMacOSInfo On tblMacOSInfo.AssetID = tblAssets.AssetID Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID, Max(tblErrors.Teller) As ErrorID From tblErrors Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID = ScanningError.ID Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype = tblErrors.ErrorType Where Software.softwareName Like '%Google Chrome%' And tblState.Statename = 'Active' Union Select Top 1000000 tblAssets.AssetID, tblAssets.AssetName, tblAssets.Domain, tsysAssetTypes.AssetTypename As AssetType, tblLinuxUser.UserName, tblAssets.Userdomain, tsysAssetTypes.AssetTypeIcon10 As icon, tblAssets.IPAddress, subquery1.Software, subquery1.Version, subquery1.Publisher, tsysIPLocations.IPLocation, tblAssetCustom.Manufacturer, tblAssetCustom.Model, tblLinuxSystem.OSRelease As OS, tblAssets.Version As OSVersion, Case When tblErrors.ErrorText Is Not Null Or tblErrors.ErrorText != '' Then 'Scanning Error: ' + tsysasseterrortypes.ErrorMsg Else '' End As ScanningErrors, tblAssets.Lastseen As [Last successful scan], tblAssets.Lasttried As [Last scan attempt], '#ffadad' As backgroundcolor From tblAssets Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID Inner Join tsysAssetTypes On tsysAssetTypes.AssetType = tblAssets.Assettype Inner Join tsysIPLocations On tsysIPLocations.LocationID = tblAssets.LocationID Inner Join tblState On tblState.State = tblAssetCustom.State Inner Join tblLinuxSystem On tblAssets.AssetID = tblLinuxSystem.AssetID Inner Join tblLinuxUser On tblAssets.AssetID = tblLinuxUser.AssetID Inner Join tblLinuxUserLogon On tblLinuxUserLogon.Id = tblLinuxUser.id Inner Join (Select tblLinuxUser.AssetId, Max(tblLinuxUserLogon.LogonTime) As MaxLogontime From tblLinuxUser Inner Join tblLinuxUserLogon On tblLinuxUserLogon.Id = tblLinuxUser.id Group By tblLinuxUser.assetid) As subquery2 On subquery2.MaxLogontime = tblLinuxUserLogon.LogonTime Inner Join (Select tblSoftwareUni.softwareName As Software, tblSoftwareUni.SoftwarePublisher As Publisher, tblLinuxSoftware.LastChanged, tblLinuxSoftware.assetid, Case When tblLinuxSoftware.Version Like '%-%' Then Left(tblLinuxSoftware.Version, CharIndex('-', tblLinuxSoftware.Version) - 1) When tblLinuxSoftware.Version Like '%R%' Then Left(tblLinuxSoftware.Version, CharIndex('R', tblLinuxSoftware.Version) - 1) Else tblLinuxSoftware.Version End As Version From tblLinuxSoftware Inner Join tblSoftwareUni On tblSoftwareUni.SoftID = tblLinuxSoftware.SoftwareUniID Where tblSoftwareUni.softwareName = 'google-chrome-stable') As subquery1 On subquery1.assetid = tblAssets.assetid Left Join (Select Distinct Top 1000000 tblErrors.AssetID As ID, Max(tblErrors.Teller) As ErrorID From tblErrors Group By tblErrors.AssetID) As ScanningError On tblAssets.AssetID = ScanningError.ID Left Join tblErrors On ScanningError.ErrorID = tblErrors.Teller Left Join tsysasseterrortypes On tsysasseterrortypes.Errortype = tblErrors.ErrorType Where subquery1.Software = 'google-chrome-stable' And tblState.Statename = 'Active' And ((Cast(ParseName(subquery1.Version, 4) As int) < 120) Or (Cast(ParseName(subquery1.Version, 4) As int) = 120 And Cast(ParseName(subquery1.Version, 2) As int) < 6099) Or (Cast(ParseName(subquery1.Version, 4) As int) = 120 And Cast(ParseName(subquery1.Version, 2) As int) = 6099 And Cast(ParseName(subquery1.Version, 1) As int) < 129)) Order By Domain, AssetName, Software