If using the Windows Internal Database (the default) rather than full SQL Server 2005, you can download Microsoft SQL Server Management Studio Express or sqlcmd.exe and connect to the DB using this connection string: \\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query. The connection must be from the same machine. For example, to use sqlcmd to run this script: sqlcmd -S np:\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query -I scriptLocation

Visual Basic
Edit|Remove
/*
Find all updates needed by computers in a specific target group
*/

USE SUSDB
SET NOCOUNT ON
DECLARE @TargetGroup nvarchar(30)
DECLARE @Days int

-- Configure the group name as needed
SELECT @TargetGroup = 'All Computers'

-- Look up the target group
DECLARE @groupId uniqueidentifier
SELECT @groupId = ComputerTargetGroupId
	FROM PUBLIC_VIEWS.vComputerTargetGroup
	WHERE vComputerTargetGroup.Name = @TargetGroup
IF @groupId is NULL
	RAISERROR ('Invalid Target Group Name', 16, 1)

-- Find all updates needed by computers in this target group
;WITH UpdateCounts AS (SELECT vUpdate.UpdateId, COUNT(*) AS NumComputers
FROM PUBLIC_VIEWS.vComputerGroupMembership
	INNER JOIN PUBLIC_VIEWS.vComputerTarget on vComputerGroupMembership.ComputerTargetId = vComputerTarget.ComputerTargetId
	INNER JOIN PUBLIC_VIEWS.vUpdateInstallationInfoBasic on vComputerTarget.ComputerTargetId = vUpdateInstallationInfoBasic.ComputerTargetId
	INNER JOIN PUBLIC_VIEWS.vUpdate on vUpdateInstallationInfoBasic.UpdateId = vUpdate.UpdateId
WHERE
	vComputerGroupMembership.ComputerTargetGroupId = @groupId
	AND vUpdateInstallationInfoBasic.State in (2, 3, 5, 6)
GROUP BY vUpdate.UpdateId)
SELECT vUpdate.DefaultTitle as "Update Title", UpdateCounts.UpdateId as "Update ID", UpdateCounts.NumComputers as "Number computers"
FROM PUBLIC_VIEWS.vUpdate
	INNER JOIN UpdateCounts on vUpdate.UpdateId = UpdateCounts.UpdateId
ORDER BY "Number computers" DESC