SCCM SQL queries

Count missing required updates per computer

SQL query for the Configuration Manager database that counts the required software updates each computer is missing, worst first.

LanguageSQL
What it does to the systemReads only. It changes nothing.

A few computers often hold most of the missing patches. This query finds them so you can fix the worst ones first.

The result shows each computer with the number of updates it needs and the time of its last check. The highest count is at the top.

SQL
-- Show only computers that miss at least this many updates.
DECLARE @MinMissing INT = 1;

SELECT
    rs.Name0                      AS ComputerName,
    COUNT(DISTINCT ucs.CI_ID)     AS MissingUpdates,
    MAX(ucs.LastStatusCheckTime)  AS LastCheck
FROM v_UpdateComplianceStatus ucs
JOIN v_UpdateInfo ui
    ON ui.CI_ID = ucs.CI_ID
JOIN v_R_System rs
    ON rs.ResourceID = ucs.ResourceID
WHERE ucs.Status = 2            -- 2 = required, not installed
  AND ui.IsSuperseded = 0
  AND ui.IsExpired = 0
GROUP BY rs.Name0
HAVING COUNT(DISTINCT ucs.CI_ID) >= @MinMissing
ORDER BY MissingUpdates DESC, rs.Name0;

How to use it

  1. Open SQL Server Management Studio and connect to the site database.
  2. Paste the query into a new query window.
  3. Run the query to see every computer that misses at least one update.
  4. Raise @MinMissing to see only the worst computers.
  5. To count only updates you deployed, add the line AND ui.IsDeployed = 1 to the WHERE block.

Good to know

  • The count covers every update in your catalog that the computer reports as required. It includes updates you have not deployed.
  • The query skips superseded and expired updates.
  • A computer that never ran an update scan does not show. Check the scan state of those computers on its own.
software updates missing updates v_UpdateComplianceStatus v_UpdateInfo
✉

Get new articles in your inbox

SCCM guides, AI tools, automation tips — sent when published. No spam.