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


IF @releaseId = 15 OR @releaseId = 16
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; SELECT count(id) as dlpEnabledClientCount from app_client C WITH(NOLOCK) WHERE EXISTS(SELECT 1 FROM APP_ClientProp WITH(NOLOCK) where componentNameId = C.id AND attrName = ''enableDLP'' AND attrVal = N''1'' AND modified = 0)
OR EXISTS(( SELECT top 1 1 FROM DlpGroupProp WITH(NOLOCK) WHERE groupid IN( SELECT id FROM APP_ClientGroup CG WITH(NOLOCK), APP_ClientGroupAssoc CGA WITH(NOLOCK)
                                                                                                                    WHERE CGA.clientId = C.id
                                                                                                                        AND CGA.clientGroupId = CG.id )
                                                                                                             AND attrName = ''enableDLP''
                                                                                                             AND attrVal = ''1'' )) ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [dlpEnabledClientCount] AS '@dlpEnabledClientCount' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10264'), 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')) 
