--- Please follow the below comments to insert SQL statements.

--------- BEGIN - GENERATED CODE, PLEASE DO NOT MODIFY ---------

SET NOCOUNT ON

DECLARE @LogDate AS BIGINT = dbo.GetUnixTime(GETUTCDATE())
DECLARE @queryId AS INTEGER = 260
DECLARE @surveyXML NVARCHAR(MAX)

--------- END - GENERATED CODE ---------



--------- BEGIN SURVEY QUERY ---------

--------- Insert your SQL statements here 

DECLARE @csRelId INT = (SELECT releaseId FROM APP_Client WITH(NOLOCK) WHERE id = 2)
DECLARE @spVersion BIGINT = (SELECT MAX(CASE WHEN HighestSP>100 THEN HighestSP/100 ELSE HighestSP END) FROM simInstalledPackages WITH(NOLOCK) WHERE ClientId = 2)

IF @csRelId < 16 OR @csRelId = 16 AND @spVersion < 23
BEGIN
	SET @outputXML = NULL
	RETURN
END

IF OBJECT_ID('tempdb..#DATroubleshootingInfo') IS NOT NULL DROP TABLE #DATroubleshootingInfo
CREATE TABLE #DATroubleshootingInfo (
	LibraryId INT, 
	LibraryName NVARCHAR(256), 
	MountPathId INT, 
	MountPathName NVARCHAR(256), 
	LibraryTypeId INT,
	PendingDeletes INT, 
	ProblemFlag BIGINT,
	JobRetentionFlag BIGINT,
	ProblemDescription NVARCHAR(max),
	Recommendation NVARCHAR(max),
	Doclink NVARCHAR(max),
	Severity INT
)

INSERT INTO #DATroubleshootingInfo
EXEC DAGetTroubleshootingInfo 0

DECLARE @DATroubleshootingInfoXml XML
SELECT  @DATroubleshootingInfoXml =
(
	SELECT 	LibraryId AS '@LibraryId', 
	        MountPathId AS '@MountPathId', 
	        MountPathName AS '@MountPathName', 
	        PendingDeletes AS '@PendingDeletes', 
	        ProblemFlag AS '@ProblemFlag',
	        JobRetentionFlag AS '@JobRetentionFlag',
	        ISNULL(ProblemDescription, '') AS '@ProblemDescription',
	        ISNULL(Recommendation, '') AS '@Recommendation',
	        ISNULL(Doclink, '') AS '@Doclink',
	        ISNULL(Severity, 0) AS '@Severity'	
	FROM	#DATroubleshootingInfo
	FOR XML PATH ('Info') 
)

SET @surveyXML = (
	SELECT 
		@DATroubleshootingInfoXml
	FOR XML PATH ('DATroubleshootingInfo') 
)

--------- END SURVEY QUERY ---------

--------- BEGIN - GENERATED CODE, PLEASE DO NOT MODIFY ---------

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')
)

SET NOCOUNT OFF

--------- END - GENERATED CODE ---------