Reporting

SCCM 2007 SQL 查詢程式碼 - 需要幫助

  • July 11, 2015

我正在嘗試編寫一份報告,在該報告中我獲取顯示所有具有維護視窗的伺服器集合的數據。我想這樣做是只顯示那些電腦也是我的“所有伺服器”集合的成員的伺服器集合。以便將它們辨識為伺服器。我不能使用像“%Server%”這樣的作業系統標題,因為其中一些電腦也是 Windows 7,但被用作伺服器角色。

這是我想出的程式碼,但輸出是空白的。任何幫助都會非常感激。非常感謝

Select Distinct
   v_Collection.CollectionID as [Collection ID],
   v_Collection.Name as [Collection Name],
   v_ServiceWindow.Description as [Maintenance Window Description], 
   v_ServiceWindow.StartTime as [Maintenance Window Start Time], 
   v_ServiceWindow.Duration as [Maintenance Window Duration]
From v_Collection Join v_ServiceWindow on 
       v_ServiceWindow.CollectionID = v_Collection.CollectionID
Join v_FullCollectionMembership on 
       v_FullCollectionMembership.CollectionID = v_ServiceWindow.CollectionID 
Where v_FullCollectionMembership.Name In
       (
        Select Distinct v_Collection.CollectionID
        From v_Collection
        Where v_Collection.CollectionID = 'XYZ'
       )
ORDER BY [Collection ID];

糟糕,我忘記輸入我使用的程式碼,對此感到抱歉。這是對我有用的程式碼:

選擇

v_FullCollectionMembership.Name as [Computername],
v_Collection.Name as [Collections With Maintenance Windows], 
v_ServiceWindow.Description as [Maintenance Description], 
v_ServiceWindow.StartTime as [Maintenance Window Start Time], 
v_ServiceWindow.Duration as [Maintenance Window Duration],
v_GS_OPERATING_SYSTEM.Caption0 as [Operating System]

v_ServiceWindow  
Join 
v_Collection on v_Collection.CollectionID = v_ServiceWindow.CollectionID
Join
v_FullCollectionMembership on v_FullCollectionMembership.CollectionID = v_ServiceWindow.CollectionID
Join
v_GS_OPERATING_SYSTEM on v_GS_OPERATING_SYSTEM.ResourceID = v_FullCollectionMembership.ResourceID
Join
v_R_System on v_R_System.ResourceID = v_FullCollectionMembership.ResourceID

在哪裡

(v_GS_OPERATING_SYSTEM.Caption0 Like '%Server%')
or
(v_FullCollectionMembership.Name Like 'WN%')

訂購方式

[Computername]

如果你執行以下命令,你看到你的伺服器了嗎?

Select Distinct
v_Collection.CollectionID as [Collection ID],
v_Collection.Name as [Collection Name],
v_ServiceWindow.Description as [Maintenance Window Description], 
v_ServiceWindow.StartTime as [Maintenance Window Start Time], 
v_ServiceWindow.Duration as [Maintenance Window Duration]
From v_Collection Join v_ServiceWindow on 
       v_ServiceWindow.CollectionID = v_Collection.CollectionID
Join v_FullCollectionMembership on 
       v_FullCollectionMembership.CollectionID = v_ServiceWindow.CollectionID 
ORDER BY [Collection ID];

如果是這樣,您的WHERE條款正在消除所需的伺服器。執行以下命令來確定要在您的WHERE子句中使用的集合的名稱:

        Select Distinct v_Collection.CollectionID, v_Collection.*
        From v_Collection;

引用自:https://dba.stackexchange.com/questions/50530