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



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

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

SET @surveyXML = (
	SELECT 
		p.simPackageID AS '@PkgID',
		pName.Name AS '@PkgName',
		COUNT (c.id)AS '@ClientCounts' 
	FROM APP_Client AS c
		INNER JOIN	simInstalledPackages AS p
			ON p.ClientId=c.id
			AND p.simPackageID IN (252, 726, 1174, 1135) --N_WIN_PACKAGE_DM2_WEB_SERVICE = 252, N_WIN_PACKAGE_WEB_CONSOLE=726, N_UNIX_PACKAGE_DM2_WEB_SERVICE = 1174, N_UNIX_PACKAGE_WEB_CONSOLE=1135,
			AND c.status != 2
			AND p.OpType IN ('Install', 'ReInstall', 'Package Sync', 'Release Upgrade')
		INNER JOIN simPackage AS pName
			ON pName.id = p.simPackageID
	GROUP BY p.simPackageID, pName.Name
	FOR XML PATH ('WebPackageInfo') 
)

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