DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
DECLARE @queryId AS INTEGER = 10269
DECLARE @surveyXML nvarchar(MAX) 
 
DECLARE @temptbl table 
(
[Operating System] nvarchar(max),[Number of MediaAgents] int
)
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; IF object_id(''tempdb.dbo.#temp'') is not null DROP TABLE #temp

CREATE TABLE #temp(osname VARCHAR(255));

INSERT INTO #temp SELECT dbo.GetClientOSName(cl.id,NULL) FROM APP_client cl WITH (NOLOCK) INNER JOIN MMHost mh WITH (NOLOCK) ON cl.id = mh.ClientId AND mh.ClientID <> 1;

SELECT osname AS ''Operating System'',count(*) AS ''Number of MediaAgents'' FROM #temp GROUP BY osname;

IF object_id(''tempdb.dbo.#temp'') is not null DROP TABLE #temp ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [Operating System] AS '@Col_-2060125650',[Number of MediaAgents] AS '@Col_600635328' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10269'), type
)
  FOR XML PATH ('SurveyResults') 
)

DECLARE @EndTime AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
SET @outputXML = (SELECT @queryId AS '@QueryId', @EndTime AS '@LogDate', (@EndTime - @LogDate) AS '@QueryRunningTime', @surveyXML FOR XML PATH('Rpt_CSSXMLDATA')) 
