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


IF @releaseId = 16
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; SELECT TOP 1 CAST(xml.sp.value(''@spVersion'', ''FLOAT'') AS INT) AS ''Installation ISO''
FROM GXGlobalParam AS G, simXMLRequest AS X
OUTER APPLY X.xmlBlob.nodes(''/CVInstallManager_ClientsComposition/patchInformation'') AS xml(sp)
WHERE X.clientId IN (
	SELECT TOP 1 ClientId 
	FROM MMDeviceController 
	WHERE Folder = ''/ws/glus'' 
	ORDER BY ClientId ASC)
AND G.name = ''CSApplianceVM'' AND G.value = 1
ORDER BY X.OpTimeUTC, X.id ASC ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [Installation ISO] AS '@Col_-124543585' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10240'), 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')) 
