DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
DECLARE @queryId AS INTEGER = 10202
DECLARE @surveyXML nvarchar(MAX) 
 
DECLARE @temptbl table 
(
[CS Failover Count] int,[HAC Count] int
)
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; DECLARE @csfailOverCount INT = 0
DECLARE @hacCount INT = 0
SELECT @csfailOverCount = COUNT(*) FROM simInstalledPackages WHERE simpackageid = 24
SELECT @hacCount = COUNT(*) FROM simInstalledPackages WHERE simpackageid = 725

SELECT @csfailOverCount AS ''CS Failover Count'', @hacCount AS ''HAC Count''  ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [CS Failover Count] AS '@Col_-1659901423',[HAC Count] AS '@Col_640455609' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10202'), 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')) 
