我试图使用SQL从SCCM返回Windows update合规性数据,我已从内置的SSRS报告中提取查询。
我没有为每个@colname(计算机组)运行单独的查询,而是试图通过将@colname声明为表并插入多个值来组合成一个查询。
SQL中返回的错误为:
消息512,16级,状态1,第6行
子查询返回了多个值。当子查询后跟=,!=,时,不允许这样做<<=>>=或者当子查询用作表达式时。
我的代码:
DECLARE @title VARCHAR(500);
DECLARE @colname TABLE (name VARCHAR(100));
SET @title = 'ADR | Workstation Software Updates 2017-12-14 09:01:38';
INSERT INTO @colname
VALUES ('All Alpha Workstations'), ('All Beta Workstations'), ('All Delta Workstations');
SELECT DISTINCT
COUNT(*) [Total Clients], li.title, coll.name,
SUM(CASE WHEN ucs.status = 3 OR ucs.status = 1 THEN 1 ELSE 0 END) AS 'Installed / Not Applicable',
SUM(CASE WHEN ucs.status = 2 THEN 1 ELSE 0 END) AS 'Required',
SUM(CASE WHEN ucs.status = 0 THEN 1 ELSE 0 END) as 'Unknown',
ROUND((CAST(SUM(CASE WHEN ucs.status = 3 OR ucs.status = 1 THEN 1 ELSE 0 END) AS float) / COUNT(*)) * 100, 2) AS 'Success %',
ROUND((CAST(COUNT(CASE WHEN ucs.status NOT IN ('3', '1') THEN '*' END) AS FLOAT) / COUNT(*)) * 100, 2) AS 'Not Success%'
FROM
v_Update_ComplianceStatusAll UCS
INNER JOIN
v_r_system sys ON ucs.resourceid = sys.resourceid
INNER JOIN
v_FullCollectionMembership fcm ON ucs.resourceid = fcm.resourceid
INNER JOIN
v_collection coll ON coll.collectionid = fcm.collectionid
INNER JOIN
v_AuthListInfo LI ON ucs.ci_id = li.ci_id
WHERE
li.title = @title
AND coll.name = (SELECT name FROM @colname) --and ucs.status=2
GROUP BY
li.title, coll.name
ORDER BY
1
感谢您的帮助。
谢谢