‎11-16-2018 12:06 PM
Select Top 1000000 *,
Case
When Drives.[%SpaceLeft] < 11 Then '#f7caca'
When Drives.[%SpaceLeft] <= 15 Then '#f7f0ca'
Else '#ffffff'
End As backgroundcolor
From (Select tblAssets.AssetID,
tblAssets.AssetName,
tblAssets.Domain,
Coalesce(tsysOS.Image, tsysAssetTypes.AssetTypeIcon10) As icon,
tblAssets.IPAddress,
tsysIPLocations.IPLocation,
tblAssetCustom.Manufacturer,
tblAssetCustom.Model,
tsysOS.OSname As OS,
tblAssets.Lastseen,
tblAssets.Lasttried,
tblDiskdrives.Caption As [Drive/Filesystem],
Cast(tblDiskdrives.Freespace / 1024 / 1024 / 1024 As numeric) As FreeGB,
Cast(tblDiskdrives.Size / 1024 / 1024 / 1024 As numeric) As TotalSizeGB,
Ceiling(tblDiskdrives.Freespace / (Case tblDiskdrives.Size
When 0 Then 1
Else tblDiskdrives.Size
End) * 100) As [%SpaceLeft],
Null As [Linux Mount Point]
From tblAssets
Inner Join tblDiskdrives On tblAssets.AssetID = tblDiskdrives.AssetID
Inner Join tblComputersystem On
tblAssets.AssetID = tblComputersystem.AssetID
Inner Join tblAssetCustom On tblAssets.AssetID = tblAssetCustom.AssetID
Inner Join tblState On tblState.State = tblAssetCustom.State
Inner Join tsysAssetTypes On tsysAssetTypes.AssetType =
tblAssets.Assettype
Inner Join tsysIPLocations On tsysIPLocations.LocationID =
tblAssets.LocationID
Left Join tsysOS On tblAssets.OScode = tsysOS.OScode
Where tblState.Statename = 'Active' And Case tblDiskdrives.DriveType
When 3 Then 'Local Disk'
End = 'Local Disk'
Union
Select tblAssets.AssetID,
tblAssets.AssetName,
tblAssets.Domain,
tsysAssetTypes.AssetTypeIcon10 As icon,
tblAssets.IPAddress,
tsysIPLocations.IPLocation,
tblAssetCustom.Manufacturer,
tblAssetCustom.Model,
tblLinuxSystem.OSRelease,
tblAssets.Lastseen,
tblAssets.Lasttried,
tblLinuxHardDisks.Filesystem As [Drive/Filesystem],
(100 - Cast(Replace(tblLinuxHardDisks.Percentage, '%', '') As bigint)) *
Cast(tblLinuxHardDisks.Size As bigint) / 100 As FreeGB,
Cast(tblLinuxHardDisks.Size As numeric) As TotalSizeGB,
100 - Cast(Replace(tblLinuxHardDisks.Percentage, '%', '') As numeric) As
[%SpaceLeft],
tblLinuxHardDisks.MountedOn As [Linux Mount Point]
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 tblLinuxSystem.AssetID = tblAssets.AssetID
Inner Join tblLinuxHardDisks On tblLinuxHardDisks.AssetID =
tblAssets.AssetID
Where tblState.Statename = 'Active') Drives
Where Drives.[%SpaceLeft] <= 15
Order By Drives.[%SpaceLeft],
Drives.AssetName
‎08-23-2019 05:16 PM
‎01-07-2019 03:28 PM
‎01-04-2019 08:39 PM
‎03-01-2023 07:27 PM
Use try_cast.
In Sql Server 2012 and up it will return null
when the conversion fails instead of an error if the value isn't numeric.
tblLinuxHardDisks.Filesystem As [Drive/Filesystem],
(100 - Try_Cast(Replace(tblLinuxHardDisks.Percentage, '%', '') As bigint)) *
Try_Cast(tblLinuxHardDisks.Size As bigint) / 100 As FreeGB,
Try_Cast(tblLinuxHardDisks.Size As numeric) As TotalSizeGB,
100 - Try_Cast(Replace(tblLinuxHardDisks.Percentage, '%', '') As numeric) As
[%SpaceLeft],
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now