我们正在推出连接到新服务器的新Symantec客户端。我已经构建了一个显示推出状态的报告。
到目前为止一切顺利。现在我尝试报告在新环境中不可见的服务器。
查询我需要的东西的数据集已经存在。
字段的服务器名称值相同。
我的目标是比较一个表:
并仅将服务器名称写入两者中不是的表中。
需要这个来检查哪个服务器没有加入新环境。
抱歉,希望你明白我的意思。 SSRS对我来说很新鲜。在随附的屏幕截图中,您可以看到我现在的第一份报告:
首次创建报告
视觉概览数据库"关系"
答案 0 :(得分:0)
你可以像这样完整的连接。
WITH
sepm_server_list
AS
(
SELECT tbl.* FROM (VALUES
( 'SEPM', 'Server1')
, ( 'SEPM', 'Server2')
, ( 'SEPM', 'Server3')
, ( 'SEPM', 'Server4')
) tbl ([DatabaseName], [ServerName])
)
,
sccm_server_list
AS
(
SELECT tbl.* FROM (VALUES
( 'SCCM', 'Server1')
, ( 'SCCM', 'Server2')
, ( 'SCCM', 'Server3')
, ( 'SCCM', 'Server5')
) tbl ([DatabaseName], [ServerName])
)
SELECT
sepm.*
, sccm.*
FROM
sepm_server_list AS sepm
FULL JOIN sccm_server_list AS sccm ON sepm.[ServerName] = sccm.[ServerName]
WHERE
1=1
AND
(
sepm.[ServerName] IS NULL
OR
sccm.[ServerName] IS NULL
)
或者您可以将它写为带有union的except语句,以获取相同列中的值。
WITH
sepm_server_list
AS
(
SELECT tbl.* FROM (VALUES
( 'SEPM', 'Server1')
, ( 'SEPM', 'Server2')
, ( 'SEPM', 'Server3')
, ( 'SEPM', 'Server4')
) tbl ([DatabaseName], [ServerName])
)
,
sccm_server_list
AS
(
SELECT tbl.* FROM (VALUES
( 'SCCM', 'Server1')
, ( 'SCCM', 'Server2')
, ( 'SCCM', 'Server3')
, ( 'SCCM', 'Server5')
) tbl ([DatabaseName], [ServerName])
)
SELECT DatabaseName = 'SEPM', A.[ServerName] FROM
(
SELECT [ServerName] FROM sepm_server_list
EXCEPT
SELECT [ServerName] FROM sccm_server_list
) A
UNION
SELECT DatabaseName = 'SCCM', B.[ServerName] FROM
(
SELECT [ServerName] FROM sccm_server_list
EXCEPT
SELECT [ServerName] FROM sepm_server_list
) B
以下是您发布的查询的示例。
WITH
sepm_server_list
AS
(
SELECT [DatabaseName] = 'SEPM', [ServerName] = COMPUTER_NAME FROM v_sem_computer
)
,
sccm_server_list
AS
(
SELECT [DatabaseName] = 'SCCM', [ServerName] = F.[Name] FROM (v_Collection AS C LEFT JOIN v_FullCollectionMembership AS F ON F.CollectionID = C.CollectionID) WHERE C.[Name] = 'ALL_SERVERS_neu'
)
SELECT DatabaseName = 'SEPM', A.[ServerName] FROM
(
SELECT [ServerName] FROM sepm_server_list
EXCEPT
SELECT [ServerName] FROM sccm_server_list
) A
UNION
SELECT DatabaseName = 'SCCM', B.[ServerName] FROM
(
SELECT [ServerName] FROM sccm_server_list
EXCEPT
SELECT [ServerName] FROM sepm_server_list
) B