The
INNER JOIN against the list of monitors limits your results to those machines that have external monitors. If you want to list
all machines, regardless of whether they have an external monitor, change it to a
LEFT JOIN.
Left Join (Select
tblMonitor.AssetID,
Count(tblMonitor.MonitorID) As numberMonitors
From
tblMonitor
Group By
tblMonitor.AssetID) countMonitor On countMonitor.AssetID = tblAssets.AssetID
LEFT JOINing opens things up too broadly. Since you haven't any filters in place limiting your results to computers, you'll get too many results. Assuming you're just after Windows machines, add an asset type filter to your WHERE clause.
Where tblAssetCustom.State = 1
AND tblAssets.Assettype = -1 -- alternatively, AND tsysAssetTypes.AssetTypename = 'Windows'
If your inventory has more than Windows machines, you'll need to adjust the asset type filter accordingly.
If you don't want to produce a NULL for machines with no monitors, you may want to adjust the Number Monitors column to deal with that.
CASE
WHEN countMonitor.numberMonitors IS NULL
THEN 0
ELSE countMonitor.numberMonitors
END As [Number monitors]
If you want to filter out servers, you'll need to add a little more to the query. Refer to
tblComputerSystem.DomainRole and, if you want descriptions,
tblDomainRoles.DomainRoleName.