DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
DECLARE @queryId AS INTEGER = 10292
DECLARE @surveyXML nvarchar(MAX) 
 
DECLARE @temptbl table 
(
[SubclientCountOfCDRAppType] int
)
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; IF EXISTS (SELECT 1 FROM app_application WITH(NOLOCK) WHERE apptypeid=84)
OR EXISTS (SELECT 1 FROM APP_CommCell WHERE csGUID in (''AF592295-40A5-492B-803C-5AAF6E340CE9'', ''0803CFCE-0948-45EA-BC42-21D6C6EAF8C7'')--return value in managed servers
)
BEGIN
	SELECT ISNULL(COUNT(DISTINCT clientid), 0) AS ''SubclientCountOfCDRAppType'' FROM app_application WITH(NOLOCK) WHERE apptypeid=84
END ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [SubclientCountOfCDRAppType] AS '@SubclientCountOfCDRAppType' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10292'), 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')) 
