DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) DECLARE @queryId AS INTEGER = 10326 DECLARE @surveyXML nvarchar(MAX) DECLARE @releaseId integer SET @releaseId = (select releaseId from APP_Client where id = 2) DECLARE @temptbl table ( [total_plan] int,[plan_with_ml_entities] int,[num_ml_entities] int,[num_ocr_enabled] int ) IF @releaseId = 16 BEGIN insert into @temptbl EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; select (select count(*) from App_Plan where type=7) as total_plan, (select count(distinct id) from (select ISNULL(T.ref.value(''@entityType'', ''int''), 0) as entityType, APD.id as id from APP_ConfigurationPolicyDetails as APD outer apply APD.policyDetails.nodes(''/eePolicy/extractionPolicy/extractionPolicyList/tags/entityDetail'') as T(ref) where detailType=6) temp_tbl where temp_tbl.entityType=1) as plan_with_ml_entities, (select COUNT(*) as num_ml_entities from (select ISNULL(T.ref.value(''@entityType'', ''int''), 0) as entityType from APP_ConfigurationPolicyDetails as APD outer apply APD.policyDetails.nodes(''/eePolicy/extractionPolicy/extractionPolicyList/tags/entityDetail'') as T(ref) where detailType=6) temp_tbl where temp_tbl.entityType=1) as num_ml_entities, (select ISNULL(sum(ISNULL(T.ref.value(''@enableImageExtraction'', ''int''), 0)),0) as numocrenabled from APP_ConfigurationPolicyDetails as APD outer apply APD.policyDetails.nodes(''/ciPolicy'') as T(ref) where detailType=5) as num_ocr_enabled ') END SET @surveyXML = ( SELECT ( SELECT [total_plan] AS '@total_plan',[plan_with_ml_entities] AS '@plan_with_ml_entities',[num_ml_entities] AS '@num_ml_entities',[num_ocr_enabled] AS '@num_ocr_enabled' FROM @temptbl FOR XML PATH ('cf_MetricsQuery10326'), 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'))