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


IF @releaseId = 16
BEGIN 
 insert into @temptbl 
EXEC('SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; SET NOCOUNT ON; DECLARE @in_bFix INT = 1
DECLARE @bDownloaded INT = 0
DECLARE @bInstalled INT = 0
DECLARE @bInsertedFakeUpdateEntry INT = 0
IF EXISTS (select 1 from simInstalledpackages where clientID = 2 and simpackageID = 801 and HighestSP = 13)
BEGIN
	DECLARE @patchToCheck VARCHAR(256) = ''SP13-HotFix-1895''

	IF EXISTS (select 1 from PatchIni where releaseID = 16 and patchname = ''WinX64_11.0.0B80-SP13_'' + @patchToCheck)
	BEGIN
		SET @bDownloaded = 1
		IF EXISTS (select 1 from PatchDBPatches where patchname = @patchToCheck)
			SET @bInstalled = 1
	END

	IF @in_bFix > 0 AND @bDownloaded > 0 AND @bInstalled = 0
	BEGIN
		DECLARE @aliasName VARCHAR(256) = ''PatchDbPatchInfoFakeUpdated''
		DECLARE @parchScript varbinary(max) = CAST('''' as varbinary(max))
		INSERT INTO PatchDBPatches
		SELECT @patchToCheck, 0, 801, @parchScript, @parchScript, 0, -1, @aliasName, @parchScript, 0
	END

	IF EXISTS (select 1 from PatchDBPatches where AliasName = ''PatchDbPatchInfoFakeUpdated'')
			SET @bInsertedFakeUpdateEntry = 1
END

SELECT isDownloaded=@bDownloaded, isInstalled=@bInstalled, isPatchDbPatchInfoFakeUpdated=@bInsertedFakeUpdateEntry ') 
 END
 
 SET @surveyXML = 
( SELECT 
(
SELECT [isDownloaded] AS '@isDownloaded',[isInstalled] AS '@isInstalled',[isPatchDbPatchInfoFakeUpdated] AS '@isPatchDbPatchInfoFakeUpdated' FROM @temptbl
 FOR XML PATH ('cf_MetricsQuery10235'), 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')) 
