DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
DECLARE @queryId AS INTEGER = 10267
DECLARE @surveyXML nvarchar(MAX) 
 
DECLARE @releaseId integer 
SET @releaseId = (select releaseId from APP_Client where id = 2) 
 
DECLARE @temptbl table 
(
[MediaAgentCount] int
)


IF @releaseId = 16
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; select COUNT(DISTINCT C.id) AS MediaAgentCount
FROM APP_Client C WITH(NOLOCK) 
JOIN simInstalledPackages SIP WITH(NOLOCK) ON C.id = SIP.ClientId
JOIN app_clientprop CP WITH(NOLOCK) ON C.id = CP.componentNameId
where  CP.attrName =''byte order'' AND CP.attrVal = ''Big-endian'' AND CP.modified = 0 AND C.releaseId = 16 AND SIP.HighestSP > 15 AND SIP.simPackageID in (51, 1301)
having COUNT(C.id) > 0 ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [MediaAgentCount] AS '@MediaAgentCount' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10267'), 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')) 
