DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
DECLARE @queryId AS INTEGER = 10315
DECLARE @surveyXML nvarchar(MAX) 
 
DECLARE @temptbl table 
(
[WebserversCount] int
)
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; SELECT COUNT(*) AS ''WebserversCount'' 
FROM App_Client C
INNER JOIN siminstalledpackages SP ON C.id = SP.ClientId
INNER JOIN simPackage S ON S.id = SP.simPackageID
WHERE S.Name =''WebServerLite'' OR S.Name=''Web Server'' ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [WebserversCount] AS '@WebserversCount' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10315'), 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')) 
