DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) DECLARE @queryId AS INTEGER = 10299 DECLARE @surveyXML nvarchar(MAX) DECLARE @releaseId integer SET @releaseId = (select releaseId from APP_Client where id = 2) DECLARE @temptbl table ( [NumStores] int,[TotalBytesAllStores] bigint ) IF @releaseId = 16 BEGIN insert into @temptbl EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; SELECT count(distinct apps.id) as NumStores,sum(jobs.totalUncompBytes) as TotalBytesAllStores FROM APP_Application apps INNER JOIN APP_Client clients ON apps.clientId = clients.id INNER JOIN APP_ClientProp clientprops ON clients.id = clientprops.componentNameId INNER JOIN APP_SubClientProp subclients ON apps.id = subclients.componentNameId INNER JOIN JMBkpStats jobs ON apps.id = jobs.appId WHERE clientprops.attrName=''System Drive Type'' and clientprops.attrVal=4 and subclients.attrName = ''Edge Drive User Id'' and jobs.status in (1, 3, 14) -- JMSUCCESS, PARTIALSUCCESS, JMSUCCESSWITHWARNINGS ') END SET @surveyXML = ( SELECT ( SELECT [NumStores] AS '@NumStores',[TotalBytesAllStores] AS '@TotalBytesAllStores' FROM @temptbl FOR XML PATH ('cf_MetricsQuery10299'), 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'))