DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE()) 
DECLARE @queryId AS INTEGER = 10258
DECLARE @surveyXML nvarchar(MAX) 
 
DECLARE @releaseId integer 
SET @releaseId = (select releaseId from APP_Client where id = 2) 
 
DECLARE @temptbl table 
(
[Subclient] int,[SubclientPolicy] int
)


IF @releaseId = 16
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; select TOP 1
(select count(distinct A.id) from APP_Application A with (nolock) inner join APP_SubClientProp Sc with (nolock) on A.id=Sc.componentNameId where Sc.modified=0 and Sc.attrName in (''sys:pre PreIfind'',''sys:post PostIfind'',''sys:pre PreSnap'',''sys:pre PreBackup'', ''sys:post PostBackup'',''sys:post PostSnap'') and A.appTypeId!=1030 and Sc.attrVal!='''') Subclient 
,
(select count(distinct A.id) from APP_Application A  with (nolock) inner join APP_SubClientProp Sc with (nolock) on A.id=Sc.componentNameId where Sc.modified=0 and Sc.attrName in (''sys:pre PreIfind'',''sys:post PostIfind'',''sys:pre PreSnap'',''sys:pre PreBackup'', ''sys:post PostBackup'',''sys:post PostSnap'') and A.appTypeId=1030 and Sc.attrVal!='''' ) SubclientPolicy
from APP_Application ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [Subclient] AS '@Subclient',[SubclientPolicy] AS '@SubclientPolicy' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10258'), 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')) 
