Building a SQL Server Version and Patch Inventory with AI

Somewhere in your fleet there’s an instance running SQL Server 2017 CU29 while every other 2017 box is on CU31. You probably don’t know which one. I didn’t either, until I built a version inventory that actually parsed build numbers into something a human can act on.

The raw information is easy to get — @@VERSION and SERVERPROPERTY() give you everything. The hard part is turning “14.0.3465.1” into “SQL Server 2017 CU31” and knowing that “14.0.3456.2” means you’re two CUs behind. That’s exactly the kind of tedious mapping work an AI agent handles well.

The Prompt

What the Agent Produced

The agent generated a clean script with a CTE-based version mapping table and the SERVERPROPERTY calls. It used CONVERT(nvarchar(128), SERVERPROPERTY(...)) consistently, which I appreciated — SERVERPROPERTY returns sql_variant, and without explicit conversion you get odd behavior in result sets.

The end-of-support flagging was straightforward: a CASE expression checking the major version number. The agent correctly noted that SQL Server 2012 (11.x) and 2014 (12.x) are out of both mainstream and extended support, while 2016 (13.x) is in extended support only.

What I changed:

  • Added the build number for the latest CU of each version. The agent’s first draft only mapped major versions, not specific CU builds. I wanted to see “2 CUs behind” at a glance. This required a reference table of current CU build numbers, which the agent populated — but I verified every entry against the Microsoft SQL Server build list on Microsoft Learn because getting a build number wrong defeats the entire purpose.
  • Pulled OS version from @@VERSION parsing. The agent initially skipped this, but knowing which instances are running on Server 2016 vs. 2022 matters for planning.
  • Added SERVERPROPERTY('IsClustered') and SERVERPROPERTY('ComputerNamePhysicalNetBIOS') to identify FCI nodes — useful for patch planning when you need to know which physical node is active.

The Final Script

This gives you one row per instance with everything you need for patch compliance reporting. The FullVersionString column includes the OS version embedded in @@VERSION output — not pretty to parse, but it’s there when you need it.

Scaling to the Fleet

The per-instance query above is designed to be wrapped in PowerShell for fleet-wide collection. The pattern from Post 5 applies directly:

The try/catch matters — the one decommissioned server in your list that refuses connections shouldn’t kill the entire collection run. You’ll see it in the output as CONNECTION FAILED and deal with it separately.

What This Tells You

Once you’ve got the inventory, the conversations it enables are valuable:

  • Patch compliance: “We have 47 instances, and 3 are more than two CUs behind our approved baseline.” That’s a concrete statement you can bring to change management.
  • Support planning: “We still have 6 instances on SQL Server 2017, which enters end of extended support in October 2027. Here’s the migration priority list.” (See Post 11 for how the agent can help with migration planning.)
  • License optimization: Spotting instances running Enterprise edition that could run on Standard saves real money.

Keeping It Current

The version mapping table needs updating when Microsoft releases new CUs. I asked the agent to include a comment at the top of the script with the “last verified” date and a link to the Microsoft Learn build list page. When you update CU baselines, you update one VALUES clause and the date stamp.

A word of caution: don’t rely on the AI agent to know the current CU build numbers. The agent’s training data has a cutoff, and Microsoft ships CUs on a regular cadence. Always verify build numbers against the official build list on Microsoft Learn. The agent is great at writing the structure of the query — the build number data is your responsibility.

Try This Yourself

Run the version inventory query on a single instance first to confirm the output makes sense. Then expand to your fleet with the PowerShell wrapper. Most DBAs discover at least one instance that’s further behind on patches than they expected — or running an edition they didn’t realize.

If you want to go further, ask the agent to add a column comparing each instance’s build number against your organization’s approved CU baseline. That turns a simple inventory into a compliance report you can hand to management — and it’s one follow-up prompt away.


Part of the ALTER DBA ADD AGENT series.