SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr

Let’s find out SCCM Patch Status SQL Query Based on Particular Collection. I have seen many questions in HTMDForum that we want the patch report, how to write a SQL query to write a report on patching, etc.

In this post, you will learn how to make a working SCCM patch status SQL query to find the patch status from your configuration manager (a.k.a ConfigMgr) database. You can customize the query as per your needs.

The following is a sample query that will help you understand the tables and views required to get the SCCM patching report working. Hence, we have done a formidable job for you.

When setting up your query, remember to replace the Collection ID, Article ID, and, optionally, the BulletinID to ensure that the query works correctly. This customization will help tailor the query to your needs and provide you with relevant information.

Patch My PC
Index
SCCM Patch Status SQL Query
Results – SCCM Patch Status SQL Query Based on Particular Collection
SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr – Table 1

NOTE! – Many other SCCM custom reports are available from Karthikeyan in the following post. SQL Query All SCCM Applications with no Deployments | ConfigMgr.

SCCM Patch Status SQL Query

Once you have initiated the client push installation method, you can track the patch installation status (a.k.a. patching) using the following query. This is the simplest way to get the patch reports from ConfigMgr.

Adaptiva
  • Open the SQL Management Studio.
  • Click on the New Query button.
  • Select the CM_MEM database from the drop-down menu.
    • MEM is the ConfigMgr site code.
  • Copy the following SQL query to find the report for particular patches.
  • Click on the Execute button.
SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr - Fig.1
SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr – Fig.1

NOTE! – Make sure to replace collection IDs, Article IDs, and Bulletin IDs before running the query.

/*Selected KB Article ID patch required or installed status for Specific Collection ID*/
Declare @Collection varchar(8)
Set @Collection = 'SMS00001' /*Enter the collection ID*/
Select
Distinct VRS.Name0 as 'MachineName',
Os.Caption0 as 'OperatingSystem',
St.SystemType00 as 'OSType',
VRS.AD_Site_Name0 as 'ADSite',
VRS.Full_Domain_Name0 as 'Domain',
VRS.User_Name0 as 'UserName',
UI.ArticleID as 'ArticleID',
UI.BulletinID as 'BulletinID',
UI.Title as 'Title',
CASE WHEN UCS.Status = 2 THEN 'Required'
WHEN UCS.Status = 3 THEN 'Installed'
ELSE 'Unknown' END AS 'KBStatus',
UI.InfoURL as 'InformationURL'
FROM v_UpdateComplianceStatus UCS
INNER JOIN v_UpdateInfo UI ON UCS.CI_ID = UI.CI_ID
INNER JOIN v_CICategories_All CIC ON UI.CI_ID = CIC.CI_ID
INNER JOIN v_CategoryInfo CI ON CIC.CategoryInstanceID = CI.CategoryInstanceID
INNER JOIN v_R_System VRS ON UCS.ResourceID = VRS.ResourceID
INNER JOIN v_GS_OPERATING_SYSTEM Os on UCS.ResourceID = Os.ResourceID
INNER JOIN Computer_System_DATA St on UCS.ResourceID = st.MachineID
INNER Join v_FullCollectionMembership Col on UCS.ResourceID = Col.ResourceID
WHERE VRS.Operating_System_Name_and0 like '%Workstation%'
and Col.CollectionID = @Collection
and UI.articleid in ('4561600','4557957','4025338') /*Enter the article ID*/
and UI.BulletinID in ('ms17-010','ms17-008') /*Enter the Bulletin ID*/
and active0 = 1 and client0 = 1
Order by 10

Results – SCCM Patch Status SQL Query Based on Particular Collection

The SQL query for patch status is very helpful in terms of troubleshooting software update issues. I have seen many scenarios where SCCM admins struggle to install the details patches on Windows 10 devices.

SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr - Fig.2
SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr – Fig.2

Resources

We are on WhatsApp. To get the latest step-by-step guides and news updates, Join our Channel. Click here –HTMD WhatsApp.

Author

Deepak Rai is a Technical Lead with over 14 years of experience in IT. He specializes in SCCM, Intune, and Azure. Throughout his career. Deepak has worked on various platforms such as Active Directory, Exchange, Veritas NETBACKUP, Symantec Backup Exec, NDMP devices like Netapp, EMC Data Domain, Quantum using Backup Exec 2010 and 2012, and HP StorageWorks 4048 MSL G3. He also has experience in data deduplication-related troubleshooting. Ultimately, he returned to his roots as an IT Engineer focusing on SCCM technology.

12 thoughts on “SCCM Patch Status SQL Query Based on Particular Collection | ConfigMgr”

  1. Hello,

    Is it possible to know the patch installed status(Installed, Failed or timed out etc.,) along with error codes(0, 3010, 1618, etc.,)

    Example with the below fields:

    Collection Name, Host Name, OS Name, Patch Update Name, Status, Installed date

    Thank you.

    Reply
  2. Hi,
    I’m using your query, and the issue i have is that some servers that aren’t being reported
    – i checked those few odd servers not being reported, and they are a member of my “All Windows Server Collection” i am targeting
    – i thought it might be because those servers do not actually have a Software Update Group being deployed to them—which is true. However, I have other servers the query is returning which also don’t have any SUG being deployed to them. So that doesn’t seem to be the case.
    – i used the third party recast tool, and for the most part, the reported servers and unreported servers appear to have all the same collection memberships

    Any idea why a few servers are not showing up on this query?

    Reply
    • Hello Brian,

      Sure we can look into it. So first thing is if the servers which are not reporting the compliance data have SCCM Client installed and healthy in the console. If Client is healthy then we need to check if software update scan is completing for those servers and state message is being forwarded to the SCCM. For prompt response and further troubleshooting let’s take it to our forum http://forum.howtomanagedevices.com/ and we can work together to fix this issue.

      Reply
  3. Hello,

    I tried this query, it’s executing successfully but some how I am getting result only for 2 devices as install and not installed updates result. in collection we have 15 devices. Any idea for those Inactive or Noclient devices

    Reply
  4. I just found this query it is precisely what I need in time sensitive situation. However, although I know the KB is installed the query returns no results. I am trying to query for KB5040422/MS24-JUL3. I have edited the UI.articleid and UI.bulletinID, articleID with and without KB#######, bulletinid with and without upper case the query runs no errors but no results either. Any suggestions as to what I did wrong

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.