--- 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 = 113
DECLARE @surveyXML NVARCHAR(MAX)
--------- END - GENERATED CODE ---------



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

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

DECLARE @TapeLibUsed INT = 0
DECLARE @VTPolicyUsed INT = 0
DECLARE @VTEntFeatureEnabled INT = 0

IF EXISTS
(SELECT * FROM MMLibrary a WITH (NOLOCK), MMMedia b WITH (NOLOCK) WHERE a.LibraryVendor <> 'commvault' AND a.LibraryId > 0 AND LibraryTypeId = 1  AND (a.LibraryId = b.LibraryId OR a.LibraryId = b.LastWriteLibraryId) AND b.MediaTypeId <> 10001)
	SET @TapeLibUsed = 1
ELSE
	SET @TapeLibUsed = 0

IF EXISTS
(SELECT * FROM VTPolicy)
	SET @VTPolicyUsed = 1
ELSE
	SET @VTPolicyUsed = 0

IF EXISTS (SELECT * FROM LicUsage WHERE cid = 2 and lictype = 82 and opType IN ('Install', 'ReInstall', 'Package Sync', 'Release Upgrade') and (Eval = 0 or ExpiryDateUTC > getUTCDate ()))
AND EXISTS (SELECT * FROM App_Clientprop WHERE componentNameId = 2 and AttrName = dbo.GetLicensePropName(1019) and attrVal = '1' and modified = 0)
	SET @VTEntFeatureEnabled = 1
ELSE 
	SET @VTEntFeatureEnabled = 0
	
SET @surveyXML = (
	SELECT 
		@TapeLibUsed AS '@TapeLibUsed', 
		@VTPolicyUsed AS '@VTPolicyUsed', 
		@VTEntFeatureEnabled AS '@VTEntFeatureEnabled'
	FOR XML PATH ('TapeMediaInfo') 
)

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

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

DECLARE @EndTime AS BIGINT = dbo.GetUnixTime(GETUTCDATE())
--select CAST( @surveyXML as xml)
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 ---------
