→ 🚀What's New? Explore Lansweeper's Fall 2024 Updates! Fall Launch Blog !
‎10-03-2017 12:21 AM
Select Top 1000000 tblAssets.AssetID,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.AssetName,
tblOperatingsystem.Version As [OS Version],
tblRegistryReleaseID.Value As [ReleaseID],
Convert([INT], tblRegistryUBR.Value ) AS [UBR],
Convert([INT], TargetUBR.UBR) AS [UBR Target],
/* Convert([INT], tblRegistryCurrentBuildNumber.Value ) AS [CurrentBuildNumber], */
Convert(Date, lastPatchDate.lastPatchDate) AS 'LastPatchDate',
Convert(Decimal(7,2),tblAssets.Uptime / 60 / 60 / 24) As [Days up],
tblAssets.Lastseen - Convert(Decimal,tblAssets.Uptime / 60 / 60 / 24) As [Boot Time],
Cast(Cast(tblDiskdrives.Freespace As bigint) / 1024 / 1024 As numeric) [Free Space],
tblAssets.Lastseen,
Left(tblADComputers.OU, CharIndex(',', tblADComputers.OU) - 1) As OU,
'<img src="thumbnail.aspx?user=' + tblADusers.Username + '&domain=' +
tblADusers.Userdomain + '&size=12" class="rimage"/>' As Picture,
tblADusers.Displayname,
tblADusers.Username,
tblADusers.Userdomain,
tblAssetCustom.Model,
tblOperatingsystem.Caption As [OS Name],
case
WHEN tblComputersystem.Domainrole = 0 Then 'Standalone Workstation'
WHEN tblComputersystem.Domainrole = 1 Then 'Member Workstation'
WHEN tblComputersystem.Domainrole = 2 Then 'Standalone Server'
WHEN tblComputersystem.Domainrole = 3 Then 'Member Server'
WHEN tblComputersystem.Domainrole = 4 Then 'Backup Domain Controller'
WHEN tblComputersystem.Domainrole = 5 Then 'Primary Domain Controller'
ELSE Convert(varchar, tblComputersystem.Domainrole) END
AS [Domain Role],
tsysIPLocations.IPLocation,
tblAssets.Description As [LS Description],
tblADComputers.Description As [AD Description]
From tblAssets
Inner Join tblComputersystem On tblAssets.AssetID = tblComputersystem.AssetID
Left Outer Join tblADusers On tblAssets.Username = tblADusers.Username
Left Outer Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Left Outer Join tsysAssetTypes On tsysAssetTypes.AssetType =
tblAssets.Assettype
Left Outer Join tblADComputers On tblAssets.AssetID = tblADComputers.AssetID
Left Outer Join tblOperatingsystem On tblAssets.AssetID =
tblOperatingsystem.AssetID
Left Outer Join tsysIPLocations On tsysIPLocations.LocationID =
tblAssets.LocationID
Left Outer Join (
Select tblQuickFixEngineering.AssetID,
Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)) As lastPatchDate
From tblQuickFixEngineering
Where isdate(tblQuickFixEngineering.InstalledOn) = 1
Group By tblQuickFixEngineering.AssetID)
As lastPatchDate On lastPatchDate.AssetID = tblAssets.AssetID
Left Outer Join tblDiskdrives On tblAssets.AssetID = tblDiskdrives.AssetID And tblDiskdrives.Caption Like 'C%'
Left Outer Join (
Select tblRegistry.AssetID, convert([int], tblRegistry.Value) As Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'UBR' )
As tblRegistryUBR On tblAssets.AssetID = tblRegistryUBR.AssetID
Left Outer Join (
Select tblRegistry.AssetID, tblRegistry.Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'CurrentBuildNumber' )
As tblRegistryCurrentBuildNumber On tblAssets.AssetID = tblRegistryCurrentBuildNumber.AssetID
Left Outer Join (
Select tblRegistry.AssetID, Convert([INT], tblRegistry.Value) AS Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'ReleaseID' )
As tblRegistryReleaseID On tblAssets.AssetID = tblRegistryReleaseID.AssetID
Left Outer JOIN (
/* Find Second highest UBR for the version (or highest if there is only 1) */
Select
tblRegistryCurrentBuildNumber.Value As [CurrentBuildNumber],
Max(convert([int], tblRegistryUBR.Value)) AS [UBR]
From tblAssets
Join (
Select tblRegistry.AssetID, tblRegistry.Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'UBR' )
As tblRegistryUBR On tblAssets.AssetID = tblRegistryUBR.AssetID
Join (
Select tblRegistry.AssetID, tblRegistry.Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'CurrentBuildNumber' )
As tblRegistryCurrentBuildNumber On tblAssets.AssetID = tblRegistryCurrentBuildNumber.AssetID
Where tblRegistryCurrentBuildNumber.Value + '+' + tblRegistryUBR.Value Not IN (
/* Find highest version if there is more than one version */
Select
tblRegistryCurrentBuildNumber.Value + '+' + convert(Varchar, Max( convert([int], tblRegistryUBR.Value))) AS [UBR]
From tblAssets
Join (
Select tblRegistry.AssetID, tblRegistry.Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'UBR' )
As tblRegistryUBR On tblAssets.AssetID = tblRegistryUBR.AssetID
Join (
Select tblRegistry.AssetID, tblRegistry.Value
from tblRegistry
Where tblRegistry.Regkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
And tblRegistry.Valuename = 'CurrentBuildNumber' )
As tblRegistryCurrentBuildNumber On tblAssets.AssetID = tblRegistryCurrentBuildNumber.AssetID
Group By tblRegistryCurrentBuildNumber.Value
HAVING Max( tblRegistryUBR.Value) <> Min( tblRegistryUBR.Value) )
Group By tblRegistryCurrentBuildNumber.Value
) AS TargetUBR ON TargetUBR.CurrentBuildNumber = tblRegistryCurrentBuildNumber.Value
Where tblAssetCustom.State = 1
/* This is where the version and desired version are compared
use one of the two below lines. The first will include machines where data is not collected, the second will not */
And ( TargetUBR.UBR > tblRegistryUBR.Value OR tblRegistryUBR.Value IS NULL )
/* And TargetUBR.UBR > tblRegistryUBR.Value */
/* filter by OU */
/* And tblADComputers.OU Like '%OU=Workstations,%' */
/* filter by domain role */
/* AND tblComputersystem.Domainrole IN (0, 1) */
/* exclude XP */
AND tblOperatingsystem.Version Not Like '5.%'
Order By
/* put not scanned yet at end */
Case WHEN tblRegistryUBR.Value is Null Then '1' Else '0' END,
/* put servers first */
Case When tblComputersystem.Domainrole < 2 Then '1' Else '0' END,
tblOperatingsystem.Version,
tblRegistryReleaseID.Value,
tblRegistryUBR.Value,
tblOperatingsystem.Caption,
lastPatchDate.lastPatchDate
‎02-10-2018 08:24 PM
‎12-06-2017 07:11 PM
Error while saving: "There was an error parsing the query. [ Token line number = 1,Token line offset = 530,Token in error = Left ]
Left(tblADComputers.OU, CharIndex(',', tblADComputers.OU) - 1) As OU,
tblADComputers.OU As OU,
‎12-06-2017 06:04 PM
‎10-19-2017 07:58 PM
Getting the following error:
Error: The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Convert(Date, lastPatchDate.lastPatchDate) AS 'LastPatchDate',
Left Outer Join (
Select tblQuickFixEngineering.AssetID,
Max(Convert(datetime,tblQuickFixEngineering.InstalledOn)) As lastPatchDate
From tblQuickFixEngineering
Where tblQuickFixEngineering.InstalledOn Like '%/%'
Group By tblQuickFixEngineering.AssetID)
As lastPatchDate On lastPatchDate.AssetID = tblAssets.AssetID
,
lastPatchDate.lastPatchDate
‎10-19-2017 12:11 AM
‎05-30-2018 01:33 AM
comtcjm wrote:
Getting the following error:
Error: The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Am I missing something?
thanks
Where tblQuickFixEngineering.InstalledOn Like '%/%'
Where isdate(tblQuickFixEngineering.InstalledOn) = 1
Select tblQuickFixEngineering.AssetID,
tblQuickFixEngineering.InstalledOn
From tblQuickFixEngineering
Where tblQuickFixEngineering.InstalledOn <> '' and Isdate(tblQuickFixEngineering.InstalledOn) <> 1
‎10-06-2017 08:16 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now