I have a query to measure compliance that works as expected:
SELECT ALL dbo.v_R_System.Name0 AS [System Name], dbo.v_R_System.User_Name0 AS [Last LoggedOn User], dbo.v_R_System.Last_Logon_TimeStamp0 AS [Last Logon Time], dbo.v_GS_OPERATING_SYSTEM.LastBootUpTime0 AS [Last BootUp Time], dbo.v_CH_ClientSummary.LastHW AS [Last Hardware Scan], dbo.v_R_System.Operating_System_Name_and0 AS [Operating System] FROM dbo.v_R_System INNER JOIN dbo.vdcmdeploymentsystemdetails ON dbo.vdcmdeploymentsystemdetails.ResourceID = dbo.v_R_System.ResourceID INNER JOIN dbo.v_GS_OPERATING_SYSTEM ON dbo.v_GS_OPERATING_SYSTEM.ResourceID = dbo.v_R_System.ResourceID INNER JOIN dbo.v_CH_ClientSummary ON dbo.v_CH_ClientSummary.ResourceID = dbo.v_R_System.ResourceID where ((dbo.vdcmdeploymentsystemdetails.BaselineID = N'ScopeId_C5AF6DAF-5E35-4329-A1E7-1DA8052F78CB/Baseline_2c49fedd-e167-401c-a2c3-c63d68af572b' AND dbo.vdcmdeploymentsystemdetails.CollectionID = N'S02002B8') AND dbo.vdcmdeploymentsystemdetails.ComplianceState = 3)
I would like to also grab system OUs but when I just add
dbo.v_RA_System_SystemOUName.System_OU_Name0 AS [System OU] INNER JOIN dbo.v_RA_System_SystemOUName on dbo.v_RA_System_SystemOUName.ResourceID = dbo.v_R_System.ResourceID
I get multiple OU entries for all upplevel OUs that the machines are a member of. I have tried these methods http://blogs.msdn.com/b/alex_semi/archive/2009/07/29/direct-ou-in-sccm.aspx and http://blogs.msdn.com/b/alex_semi/archive/2009/07/29/direct-ou-in-sccm.aspx
SELECT ResourceID, MAX(System_OU_Name0) FROM [database].dbo.v_RA_System_SystemOUName GROUP BY ResourceID
which work fine by themselves. How can I add it to my original query though?
When I try
Max(dbo.v_RA_System_SystemOUName.System_OU_Name0) AS [System OU]
and add
GROUP BY dbo.v_R_System.ResourceID
I get an error :
An error occurred while executing the query.
Column 'dbo.v_R_System.Name0' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Any idea on how to include it correctly in the first query