我正在尝试创建 sum() 表达式,它将汇总行并将结果放入“TPM 中的总服务器”列中。看起来我无法为 sum 表达式提供正确的提要。
设计模式下的 SSRS 矩阵报告如下所示:
[TPM_scan_type] 表达式可以有 2 个值:“TPM 成功扫描”或“TPM 失败扫描”
=Switch(Fields!ScanStatus.Value = "OK","TPM Succesfull Scan",Fields!ScanStatus.Value = "FAILED!","TPM Failed Scan")
[scan_count] 表达式只是聚合每个“主要 SA”的值
=Switch(Fields!ScanStatus.Value="FAILED!",Count(Fields!ScanStatus.Value),Fields!ScanStatus.Value="OK", CountDistinct(Fields!ServerName.Value))
结果:
数据样本:
USE tempdb;
GO
IF OBJECT_ID('dbo.TPM_test') IS NOT NULL
DROP TABLE dbo.TPM_test;
GO
CREATE TABLE dbo.TPM_test
(
ServerName varchar(30) NOT NULL,
ScanStatus varchar(10) NOT NULL,
Primary_SA varchar(30) NOT NULL,
HotfixID int
);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('LDNSQLF700', 'OK', 'SA1', 157848);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('LDNSQLF700', 'OK', 'SA1', 976832);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('LDNSQLF700', 'OK', 'SA1', 234354);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('NYSQL502', 'FAILED!', 'SA1', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('PSQL1011', 'FAILED!', 'SA1', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('NTQDF002', 'OK', 'SA1', 878641);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('AUSSQL140', 'OK', 'SA2', 537990);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('AUSSQL140', 'OK', 'SA2', 1349605);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('JAP543X2', 'FAILED!', 'SA2', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EU456CLX', 'FAILED!', 'SA2', '');
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 5637965);
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 6464367) ;
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 1323123) ;
INSERT INTO dbo.TPM_test(ServerName, ScanStatus, Primary_SA, HotfixID)
VALUES('EUCTX654', 'OK', 'SA2', 1004326) ;
GO