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


IF @releaseId = 16
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; Select Count(SiteName)As NumberOfRegisteredSites, COUNT(Distinct WARS.UserID) AS NumberOfRegisteredUsers 
from WARegisteredSite AS WAR WITH (NOLOCK)
Join WARegisteredSitePermission AS WARS WITH (NOLOCK)
on WAR.ID = WARS.RegisteredSiteID  where WARS.UserID IS NOT NULL ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [NumberOfRegisteredSites] AS '@NumberOfRegisteredSites',[NumberOfRegisteredUsers] AS '@NumberOfRegisteredUsers' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10266'), 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')) 
