

--  ------------  Generated from [/big2/11.0/Build80_SP24/cxunix/source/CommServer/Db/TblScript/APP_DataStatements.script] ---------- 


SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON

SET QUOTED_IDENTIFIER ON

SET  NOCOUNT ON

DECLARE @ccDataSetId INTEGER

SET @ccDataSetId = ISNULL((SELECT datasetId from APP_DATASET where name = 'COMMCELL_DEFAULT'), 0)

DECLARE @dataSetId INTEGER 

SET @dataSetId = ISNULL((SELECT datasetId from APP_DATASET where name = 'METRICS_DEFAULT'), 0)

DECLARE @msDbDataSetId INTEGER 

SET @msDbDataSetId = ISNULL((SELECT datasetId from APP_DATASET where name = 'MSDB_DEFAULT'), 0)

DECLARE @gldbDataSetId INTEGER

SET @gldbDataSetId = ISNULL((SELECT datasetId from APP_DATASET where name = 'GATHER_LOGS_DEFAULT'), 0) 

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'COMMCELL_EXECUTE_SP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@ccDataSetId, 'COMMCELL_EXECUTE_SP', '', '<ReportPlus_OperationProperties sqlText="EXEC CV_ExecuteQuery 0, @spName, &lt;loginUserId&gt;, @param1, @param2, @param3, @param4, @param5, @param6, @param7, @param8, @param9, @param10, @param11, @param12, @param13, @param14, @param15"><parameters name="spName" dataType="0" /><parameters name="param1" dataType="0" /><parameters name="param2" dataType="0" /><parameters name="param3" dataType="0" /><parameters name="param4" dataType="0" /><parameters name="param5" dataType="0" /><parameters name="param6" dataType="0" /><parameters name="param7" dataType="0" /><parameters name="param8" dataType="0" /><parameters name="param9" dataType="0" /><parameters name="param10" dataType="0" /><parameters name="param11" dataType="0" /><parameters name="param12" dataType="0" /><parameters name="param13" dataType="0" /><parameters name="param14" dataType="0" /><parameters name="param15" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_EXECUTE_SP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_EXECUTE_SP', '', '<ReportPlus_OperationProperties sqlText="EXEC CV_ExecuteQuery 0, @spName, &lt;loginUserId&gt;, @param1, @param2, @param3, @param4, @param5, @param6, @param7, @param8, @param9, @param10, @param11, @param12, @param13, @param14, @param15"><parameters name="spName" dataType="0" /><parameters name="param1" dataType="0" /><parameters name="param2" dataType="0" /><parameters name="param3" dataType="0" /><parameters name="param4" dataType="0" /><parameters name="param5" dataType="0" /><parameters name="param6" dataType="0" /><parameters name="param7" dataType="0" /><parameters name="param8" dataType="0" /><parameters name="param9" dataType="0" /><parameters name="param10" dataType="0" /><parameters name="param11" dataType="0" /><parameters name="param12" dataType="0" /><parameters name="param13" dataType="0" /><parameters name="param14" dataType="0" /><parameters name="param15" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_EXECUTE_SP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'MSDB_EXECUTE_SP', '', '<ReportPlus_OperationProperties sqlText="EXEC CV_ExecuteQuery 0, @spName, &lt;loginUserId&gt;, @param1, @param2, @param3, @param4, @param5, @param6, @param7, @param8, @param9, @param10, @param11, @param12, @param13, @param14, @param15"><parameters name="spName" dataType="0" /><parameters name="param1" dataType="0" /><parameters name="param2" dataType="0" /><parameters name="param3" dataType="0" /><parameters name="param4" dataType="0" /><parameters name="param5" dataType="0" /><parameters name="param6" dataType="0" /><parameters name="param7" dataType="0" /><parameters name="param8" dataType="0" /><parameters name="param9" dataType="0" /><parameters name="param10" dataType="0" /><parameters name="param11" dataType="0" /><parameters name="param12" dataType="0" /><parameters name="param13" dataType="0" /><parameters name="param14" dataType="0" /><parameters name="param15" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHER_LOGS_EXECUTE_SP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@gldbDataSetId, 'GATHER_LOGS_EXECUTE_SP', '', '<ReportPlus_OperationProperties sqlText="EXEC CV_ExecuteQuery 0, @spName, &lt;loginUserId&gt;, @param1, @param2, @param3, @param4, @param5, @param6, @param7, @param8, @param9, @param10, @param11, @param12, @param13, @param14, @param15"><parameters name="spName" dataType="0" /><parameters name="param1" dataType="0" /><parameters name="param2" dataType="0" /><parameters name="param3" dataType="0" /><parameters name="param4" dataType="0" /><parameters name="param5" dataType="0" /><parameters name="param6" dataType="0" /><parameters name="param7" dataType="0" /><parameters name="param8" dataType="0" /><parameters name="param9" dataType="0" /><parameters name="param10" dataType="0" /><parameters name="param11" dataType="0" /><parameters name="param12" dataType="0" /><parameters name="param13" dataType="0" /><parameters name="param14" dataType="0" /><parameters name="param15" dataType="0" /></ReportPlus_OperationProperties>')	


END

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS set dataSetId=@gldbDataSetId WHERE NAME = 'GATHER_LOGS_EXECUTE_SP'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPT_AUDIT_COMMCELLS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPT_AUDIT_COMMCELLS', '', '<ReportPlus_OperationProperties sqlText="SELECT CommServUniqueId AS ''ID'', CommCellID, CommServName FROM RptMetricsCommCellDetails(0, @ccGroupId, 0, &lt;loginUserId&gt;, 0)"><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END

ELSE

	UPDATE	APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CommServUniqueId AS ''ID'', CommCellID, CommServName FROM RptMetricsCommCellDetails(0, @ccGroupId, 0, &lt;loginUserId&gt;, 0)"><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_RPT_AUDIT_COMMCELLS'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_LATEST_COLLECTION_TIME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_LATEST_COLLECTION_TIME', '', '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastCollectionTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastCollectionTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastCollectionTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastCollectionTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastCollectionTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastCollectionTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_LATEST_COLLECTION_TIME'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_LATEST_HEALTH_COLLECTION_TIME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_LATEST_HEALTH_COLLECTION_TIME', '', '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastHealthCollectionTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastHealthCollectionTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastHealthCollectionTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastHealthCollectionTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastHealthCollectionTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastHealthCollectionTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_LATEST_HEALTH_COLLECTION_TIME'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_LATEST_ACTIVITY_COLLECTION_TIME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_LATEST_ACTIVITY_COLLECTION_TIME', '', '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastActivityCollectionTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastActivityCollectionTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastActivityCollectionTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastActivityCollectionTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastActivityCollectionTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastActivityCollectionTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_LATEST_ACTIVITY_COLLECTION_TIME'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_LATEST_CHARGEBACK_TIME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_LATEST_CHARGEBACK_TIME', '', '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastChargeBackTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastChargeBackTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastChargeBackTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(20), LastChargeBackTime, 107) + '' '' + LTRIM(LEFT(RIGHT(CONVERT(VARCHAR(20), LastChargeBackTime, 100), 7), 5)) + '' ''+ RIGHT(CONVERT(VARCHAR(20), LastChargeBackTime, 100), 2) AS CollDate FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_LATEST_CHARGEBACK_TIME'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT CommCellID, commcellname AS ''CommCell Name'', commservversion AS ''Version'', commservGUID AS ''CommServeGUID'', commservtz AS ''TimeZone'', monitoredclientgroup AS ''ClientGroup'' FROM   Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CommCellID, commcellname AS ''CommCell Name'', commservversion AS ''Version'', commservGUID AS ''CommServeGUID'', commservtz AS ''TimeZone'', monitoredclientgroup AS ''ClientGroup'' FROM   Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_COMMCELL_DETAILS_1'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT R.commcellid, R.commcellname AS ''CommCell Name'', R.commservguid AS ''CommServeGUID'', R.commservversion AS ''Version'', R.commservtz AS ''TimeZone'', R.monitoredclientgroup AS ''ClientGroup'', R.commservedition AS ''Edition'', R.LicExpirationDate AS ''LicExpirationDate'', R.CommServIP AS ''CommServIP'', CASE WHEN CC.CurrCSIpAddress IS NULL OR LEN(CC.CurrCSIpAddress) &lt;= 0 THEN ''N/A'' ELSE CC.CurrCSIpAddress END AS ''CurrCSIpAddress'', CONVERT(NVARCHAR(12), CommServInstallDate, 107) AS ''CommServInstallDate'', R.LicenseServerFlags AS ''LicenseServerFlags'' FROM Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0) R INNER JOIN cf_CommcellIdNameMap CC ON R.CommServUniqueId = CC.ID "><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS 

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT R.commcellid, R.commcellname AS ''CommCell Name'', R.commservguid AS ''CommServeGUID'', R.commservversion AS ''Version'', R.commservtz AS ''TimeZone'', R.monitoredclientgroup AS ''ClientGroup'', R.commservedition AS ''Edition'', R.LicExpirationDate AS ''LicExpirationDate'', R.CommServIP AS ''CommServIP'', CASE WHEN CC.CurrCSIpAddress IS NULL OR LEN(CC.CurrCSIpAddress) &lt;= 0 THEN ''N/A'' ELSE CC.CurrCSIpAddress END AS ''CurrCSIpAddress'', CONVERT(NVARCHAR(12), CommServInstallDate, 107) AS ''CommServInstallDate'', R.LicenseServerFlags AS ''LicenseServerFlags'' FROM Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0) R INNER JOIN cf_CommcellIdNameMap CC ON R.CommServUniqueId = CC.ID "><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name='METRICS_COMMCELL_DETAILS_2'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_ID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_ID', '', '<ReportPlus_OperationProperties sqlText="SELECT CommCellID FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, 0, -1, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS 

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CommCellID FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, 0, -1, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name='METRICS_COMMCELL_ID'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_VERSION')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_VERSION', '', '<ReportPlus_OperationProperties sqlText="SELECT commservversion FROM Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS 

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT commservversion FROM Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name='METRICS_COMMCELL_VERSION'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_GUID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_GUID', '', '<ReportPlus_OperationProperties sqlText="SELECT commservguid AS ''CommServeGUID'' FROM Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS 

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT commservguid AS ''CommServeGUID'' FROM Rptmetricscommcelldetails(@commUniId, @ccGroupId, @surveyId, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="surveyId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name='METRICS_COMMCELL_GUID'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_DETAILS_ALL')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_DETAILS_ALL', '', '<ReportPlus_OperationProperties sqlText="SELECT * FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, 0, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS 

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT * FROM RptMetricsCommCellDetails(@commUniId, @ccGroupId, 0, &lt;loginUserId&gt;, 0)"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name='METRICS_COMMCELL_DETAILS_ALL'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_COUNT_FLAG')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_COUNT_FLAG', '', '<ReportPlus_OperationProperties sqlText="SELECT COUNT(*) AS ''Flag'' FROM RptMetricsCommCellDetails(0, @ccGroupId, 0,&lt;loginUserId&gt;,0) WHERE CommServUniqueId = @commUniId"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS 

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT COUNT(*) AS ''Flag'' FROM RptMetricsCommCellDetails(0, @ccGroupId, 0,&lt;loginUserId&gt;,0) WHERE CommServUniqueId = @commUniId"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name='METRICS_COMMCELL_COUNT_FLAG'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_WW')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_WW', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT g.SurveyGroupId AS GroupId, g.Name AS GroupName, q.QueryId AS SurveyId, q.Name AS SurverName FROM cf_CommservSurveyQueries AS q INNER JOIN cf_CommservSurveyGroupMap AS map ON map.SurveyId = q.QueryId AND ((q.Flags &amp; 1) = 1 OR (q.Flags &amp; 128) = 128) INNER JOIN cf_CommservSurveyGroups AS g ON map.GroupId = g.SurveyGroupId AND (g.Flags &amp;1 ) &lt;&gt; 1 UNION SELECT DISTINCT g.SurveyGroupId AS GroupId, g.Name AS GroupName, q.QueryId AS SurveyId, q.Name AS SurverName FROM cf_CommservSurveyQueries AS q INNER JOIN cf_CommservSurveyGroupMap AS map ON map.SurveyId = q.QueryId AND ((q.Flags &amp; 1) = 1 OR (q.Flags &amp; 128) = 128) INNER JOIN cf_CommservSurveyGroups AS g ON map.GroupId = g.SurveyGroupId AND (g.Flags &amp;1 ) = 1 inner join cf_MetricsLoggedInUsers ML on ML.UserId = &lt;loginUserId&gt; AND ML.surveycapability =1 ORDER BY g.SurveyGroupId, q.Name" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_CC')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_CC', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT g.SurveyGroupId AS GroupId, g.Name AS GroupName, q.QueryId AS SurveyId, q.Name AS SurverName FROM cf_CommservSurveyQueries AS q INNER JOIN cf_CommservSurveyGroupMap AS map ON map.SurveyId = q.QueryId AND ((q.Flags &amp; 1) = 1 or (q.Flags &amp; 64) = 64)   INNER JOIN cf_CommservSurveyGroups AS g ON map.GroupId = g.SurveyGroupId AND (g.Flags &amp;1 ) &lt;&gt; 1 UNION SELECT DISTINCT g.SurveyGroupId AS GroupId, g.Name AS GroupName, q.QueryId AS SurveyId, q.Name AS SurverName FROM cf_CommservSurveyQueries AS q INNER JOIN cf_CommservSurveyGroupMap AS map ON map.SurveyId = q.QueryId AND ((q.Flags &amp; 1) = 1 or (q.Flags &amp; 64) = 64) INNER JOIN cf_CommservSurveyGroups AS g ON map.GroupId = g.SurveyGroupId AND (g.Flags &amp;1 ) = 1 inner join cf_MetricsLoggedInUsers ML on ML.UserId = &lt;loginUserId&gt; AND ML.surveycapability =1 ORDER BY g.SurveyGroupId, q.Name" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_WW')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_WW', '', '<ReportPlus_OperationProperties sqlText="SELECT 0 AS GroupId, CASE WHEN  (F.DispFlag &amp; 16 /*REPORT_DISPLAY_CHARGEBACK*/) &gt; 0 THEN &#39;Capacity and Chargeback&#39; WHEN (F.DispFlag &amp; 32 /*REPORT_DISPLAY_AUDIT*/) &gt; 0 THEN &#39;Configuration Audit&#39; ELSE &#39;&#39; END AS GroupName, R.ReportId AS SurveyId, R.Name AS SurverName, F.DispFlag AS Flags FROM cf_WebConsoleReports R INNER JOIN dbo.RptMetricsReportsFlags(0) AS F ON R.ReportId = F.ReportId WHERE F.Status = 1 AND (F.DispFlag &amp; 1 /*REPORT_DISPLAY_WORLDWIDE_LANDING*/) = 1 AND (F.isInternal = 0 OR (SELECT surveyCapability FROM cf_MetricsLoggedInUsers WHERE userId = &lt;loginUserId&gt;) = 1) AND R.ReportId &lt; 1000 order by GroupName, SurverName " />')


END	

ELSE

	UPDATE 	APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT 0 AS GroupId, CASE WHEN  (F.DispFlag &amp; 16 /*REPORT_DISPLAY_CHARGEBACK*/) &gt; 0 THEN &#39;Capacity and Chargeback&#39; WHEN (F.DispFlag &amp; 32 /*REPORT_DISPLAY_AUDIT*/) &gt; 0 THEN &#39;Configuration Audit&#39; ELSE &#39;&#39; END AS GroupName, R.ReportId AS SurveyId, R.Name AS SurverName, F.DispFlag AS Flags FROM cf_WebConsoleReports R INNER JOIN dbo.RptMetricsReportsFlags(0) AS F ON R.ReportId = F.ReportId WHERE F.Status = 1 AND (F.DispFlag &amp; 1 /*REPORT_DISPLAY_WORLDWIDE_LANDING*/) = 1 AND (F.isInternal = 0 OR (SELECT surveyCapability FROM cf_MetricsLoggedInUsers WHERE userId = &lt;loginUserId&gt;) = 1) AND R.ReportId &lt; 1000 order by GroupName, SurverName " />'

	WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_WW'	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_CC')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_CC', '', '<ReportPlus_OperationProperties sqlText="SELECT 0 AS GroupId, CASE WHEN  (F.DispFlag &amp; 16 /*REPORT_DISPLAY_CHARGEBACK*/) &gt; 0 THEN &#39;Capacity and Chargeback&#39; WHEN (F.DispFlag &amp; 32 /*REPORT_DISPLAY_AUDIT*/) &gt; 0 THEN &#39;Configuration Audit&#39; ELSE &#39;&#39; END AS GroupName, R.ReportId AS SurveyId, R.Name AS SurverName, F.DispFlag AS Flags FROM cf_WebConsoleReports R INNER JOIN dbo.RptMetricsReportsFlags(0) AS F ON R.ReportId = F.ReportId WHERE F.Status = 1 AND (F.DispFlag &amp; 2 /*REPORT_DISPLAY_COMMCELL_LANDING*/) = 2 AND (F.isInternal = 0 OR (SELECT surveyCapability FROM cf_MetricsLoggedInUsers WHERE userId = &lt;loginUserId&gt;) = 1) AND R.ReportId &lt; 1000 order by GroupName, SurverName " />')


END	

ELSE

	UPDATE 	APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT 0 AS GroupId, CASE WHEN  (F.DispFlag &amp; 16 /*REPORT_DISPLAY_CHARGEBACK*/) &gt; 0 THEN &#39;Capacity and Chargeback&#39; WHEN (F.DispFlag &amp; 32 /*REPORT_DISPLAY_AUDIT*/) &gt; 0 THEN &#39;Configuration Audit&#39; ELSE &#39;&#39; END AS GroupName, R.ReportId AS SurveyId, R.Name AS SurverName, F.DispFlag AS Flags FROM cf_WebConsoleReports R INNER JOIN dbo.RptMetricsReportsFlags(0) AS F ON R.ReportId = F.ReportId WHERE F.Status = 1 AND (F.DispFlag &amp; 2 /*REPORT_DISPLAY_COMMCELL_LANDING*/) = 2 AND (F.isInternal = 0 OR (SELECT surveyCapability FROM cf_MetricsLoggedInUsers WHERE userId = &lt;loginUserId&gt;) = 1) AND R.ReportId &lt; 1000 order by GroupName, SurverName " />'

	WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_CC'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_ALL_SP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_ALL_SP', '', '<ReportPlus_OperationProperties sqlText="SELECT QueryId, ParserScriptName FROM cf_CommservSurveyQueries" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_SID_NAME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_SID_NAME', '', '<ReportPlus_OperationProperties sqlText="SELECT Q.QueryId AS SurveyId, Q.Name FROM cf_CommservSurveyQueries Q WITH(NOLOCK) INNER JOIN dbo.RptGetMetricsQueryFlags(0) F ON Q.QueryId =  F.QueryId WHERE F.QueryFlags &amp; 4 = 4 AND F.QueryFlags &amp; 1 &lt;&gt; 1" />')


END		

ELSE 

BEGIN

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="SELECT Q.QueryId AS SurveyId, Q.Name FROM cf_CommservSurveyQueries Q WITH(NOLOCK) INNER JOIN dbo.RptGetMetricsQueryFlags(0) F ON Q.QueryId =  F.QueryId WHERE F.QueryFlags &amp; 4 = 4 AND F.QueryFlags &amp; 1 &lt;&gt; 1" />'

	WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_SID_NAME'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_137')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_137', '', '<ReportPlus_OperationProperties sqlText="select QueryFlags as Flags from dbo.RptGetMetricsQueryFlags(137)" />')


END		

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS SET operation = '<ReportPlus_OperationProperties sqlText="select QueryFlags as Flags from dbo.RptGetMetricsQueryFlags(137)" />' WHERE NAME = 'METRICS_COMMSERVSURVEYQUERIES_FLAGS_137'

END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELLIDNAMEMAP_TOTAL_COMMCELLS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELLIDNAMEMAP_TOTAL_COMMCELLS', '', '<ReportPlus_OperationProperties sqlText="SELECT COUNT(*) AS TotalCommCellCount FROM cf_CommcellIdNameMap WHERE Flags &amp; 1 &lt;&gt; 1" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_GL_COMMCELLSURVEYSERVICES_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_GL_COMMCELLSURVEYSERVICES_1', '', '<ReportPlus_OperationProperties sqlText="SELECT ID, CommServName AS commcellname, CASE commcellsurveyservices &amp; POWER(2,6) WHEN 0 THEN ''False'' ELSE ''True'' END AS IsChecked, CASE commcellsurveyservices &amp; POWER(2,5) WHEN 0 THEN ''False'' ELSE ''True'' END AS IsChargebackChecked, CommCellID, CustomerName AS customername, commcellsurveyservices AS enabledservices FROM cf_CommcellIdNameMap WHERE ID= @commUId"><parameters name="commUId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_DETAILS_3')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_DETAILS_3', '', '<ReportPlus_OperationProperties sqlText="SELECT CommServUniqueId AS ''CommServ UniqueId'', DisplayName AS ''CommCell Name'', CommCellID AS ''CommCell ID'', CommServGUID FROM cf_SurveyResultFuncV1(146, 0, 1, NULL, NULL, &lt;loginUserId&gt;, @ccGroupId)"><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="SELECT CommServUniqueId AS ''CommServ UniqueId'', DisplayName AS ''CommCell Name'', CommCellID AS ''CommCell ID'', CommServGUID FROM cf_SurveyResultFuncV1(146, 0, 1, NULL, NULL, &lt;loginUserId&gt;, @ccGroupId)"><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>' 

	WHERE	name = 'METRICS_COMMCELL_DETAILS_3'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMCELL_UID_FROM_CCID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMCELL_UID_FROM_CCID', '', '<ReportPlus_OperationProperties sqlText="SELECT csinfo.ID AS ''CommServ UniqueId'' FROM cf_SurveyResultFuncV1(2, 0, 1, NULL, NULL, &lt;loginUserId&gt; , -1) AS resultFn INNER JOIN cf_CommcellIdNameMap csinfo WITH (NOLOCK) ON resultFn.CommServUniqueId = csinfo.ID WHERE csinfo.CommCellID=@commCellId"><parameters name="commCellId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMCELL_UID_FROM_GUID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMCELL_UID_FROM_GUID', '', '<ReportPlus_OperationProperties sqlText="SELECT csinfo.ID AS ''CommServ UniqueId'' FROM cf_SurveyResultFuncV1(2, 0, 1, NULL, NULL, &lt;loginUserId&gt; , -1) AS resultFn INNER JOIN cf_CommcellIdNameMap csinfo WITH (NOLOCK) ON resultFn.CommServUniqueId = csinfo.ID WHERE csinfo.CommServGUID=@guid"><parameters name="guid" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CC_NAME_VERSION')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CC_NAME_VERSION', '', '<ReportPlus_OperationProperties sqlText="SELECT CommServName As ''CommCellName'',CommServVersion AS ''Version'' FROM cf_CommcellIdNameMap WHERE ID = @commUniId"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CC_ENABLED_SERVICES')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CC_ENABLED_SERVICES', '', '<ReportPlus_OperationProperties sqlText="SELECT  CASE WHEN (csInfo.CommCellSurveyServices &amp; 1) =1 THEN ''Yes'' ELSE ''No'' END AS ''HEALTH'', CASE WHEN (csInfo.CommCellSurveyServices &amp; 4) =4 THEN ''Yes'' ELSE ''No'' END AS ''ACTIVITY'', CASE WHEN (csInfo.CommCellSurveyServices &amp; 2) =2 THEN ''Yes'' ELSE ''No'' END AS ''UPGRADE_CHECK'', CASE WHEN (csInfo.CommCellSurveyServices &amp; 16) =16 THEN ''Yes'' ELSE ''No'' END AS ''AUDIT'', CASE WHEN (csInfo.CommCellSurveyServices &amp; 32) =32 THEN ''Yes'' ELSE ''No'' END AS ''CHARGEBACK'' FROM cf_CommcellIdNameMap csinfo WITH (nolock) INNER JOIN dbo.cf_SurveyResultFuncV1(146,  @commUniId, 1, NULL, NULL, &lt;loginUserId&gt;, -1) AS resultView  ON resultView.CommServUniqueId = csinfo.ID "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CUSTOMER_NAME_FOR_UID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CUSTOMER_NAME_FOR_UID', '', '<ReportPlus_OperationProperties sqlText="SELECT CASE WHEN CustomerName LIKE '''' THEN CommServName ELSE CustomerName END AS CustomerName FROM cf_CommcellIdNameMap WHERE ID = @commUniId"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_GLOBALCOSTPARAMVIEW_ALL')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_GLOBALCOSTPARAMVIEW_ALL', '', '<ReportPlus_OperationProperties sqlText="SELECT * FROM cf_GlobalCostParamView" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETCOMMCELLCOUNT_CC_COUNT')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETCOMMCELLCOUNT_CC_COUNT', '', '<ReportPlus_OperationProperties sqlText="SELECT dbo.RptGetCommcellCount(@reportType, &lt;loginUserId&gt;, @ccGroupId, @showAllCommcell, @tenant) AS commCellCount"><parameters name="reportType" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="showAllCommcell" dataType="5" /><parameters name="tenant" dataType="0" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="SELECT dbo.RptGetCommcellCount(@reportType, &lt;loginUserId&gt;, @ccGroupId, @showAllCommcell, @tenant) AS commCellCount"><parameters name="reportType" dataType="5" /><parameters name="ccGroupId" dataType="5" /><parameters name="showAllCommcell" dataType="5" /><parameters name="tenant" dataType="0" /></ReportPlus_OperationProperties>' WHERE name = 'METRICS_RPTGETCOMMCELLCOUNT_CC_COUNT'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYBILLINGENTITY_ID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYBILLINGENTITY_ID', '', '<ReportPlus_OperationProperties sqlText="SELECT ID FROM cf_SurveyBillingEntity WHERE Name = @tagName"><parameters name="tagName" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_HEALTH_PARAMS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_HEALTH_PARAMS', '', '<ReportPlus_OperationProperties sqlText="SELECT QueryId, QueryName As ''Parameter'', ThresholdName AS ''Threshold'', GoodThresholdText AS ''Good'', WarningThresholdText AS ''Warning'', CriticalThresholdText AS ''Critical'', WarningThreshold, CriticalThreshold, ThresholdMin, ThresholdMax, CASE WHEN (warningthreshold != -1 AND criticalthreshold != -1) THEN ''Yes'' ELSE ''No'' END AS Editable, DescriptionText FROM cf_ReportParameterView ORDER BY Editable" />')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_HEALTH_PARAMS_ALL_GROUPS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_HEALTH_PARAMS_ALL_GROUPS', '', '<ReportPlus_OperationProperties sqlText="SELECT ParameterName AS ''Parameter'', ThresholdName AS ''Threshold'', GoodThresholdText AS ''GoodText'', WarningThresholdText AS ''WarnText'', CriticalThresholdText AS ''CriticalText'', WarningThreshold AS Warning, CriticalThreshold AS Critical, ParamId AS Id, ThresholdMin AS tmin, ThresholdMax AS tmax, ParamSortOrder AS ''ParamSortOrder&lt;DONOTSHOW&gt;'', QueryGroupId AS ''QueryGroupId&lt;DONOTSHOW&gt;'' FROM cf_ReportParameterView" />')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_REPORTPARAMETERVIEW_ORDERBY_GID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_REPORTPARAMETERVIEW_ORDERBY_GID', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT(QueryGroupId) AS QID, QueryGroupName FROM cf_reportparameterview ORDER BY querygroupid" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_HEALTH_PARAMS_STATUS_ROW')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_HEALTH_PARAMS_STATUS_ROW', '', '<ReportPlus_OperationProperties sqlText="SELECT * FROM dbo.RptMetricsThresholdInfo(@commUniId,@queryId)">  <parameters name="queryId" dataType="5" /> <parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE 

BEGIN

	UPDATE APP_DataStatements

	SET operation='<ReportPlus_OperationProperties sqlText="SELECT * FROM dbo.RptMetricsThresholdInfo(@commUniId,@queryId)">  <parameters name="queryId" dataType="5" /> <parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name = 'METRICS_HEALTH_PARAMS_STATUS_ROW'

END 

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYHEALTHPARAM_PID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYHEALTHPARAM_PID', '', '<ReportPlus_OperationProperties sqlText="SELECT ISNULL(paramId, @queryId) AS paramID FROM cf_SurveyHealthParam WHERE queryId = @queryId"><parameters name="queryId" dataType="5" /><parameters name="queryId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETCOMMCELLGROUPS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETCOMMCELLGROUPS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT GroupId AS ''GroupId&lt;DONOTSHOW&gt;'',  GroupName AS ''Group Name&lt;CommCellGroup&gt;'', GroupDescription AS ''Group Description&lt;DONOTSHOW&gt;'', CommCellCount as ''Number of CommCells'', ActiveClients as ''Active Clients'', SLA as ''SLA (%)'',  GroupCreatedBy as ''Created By&lt;HIDDEN&gt;'',  GroupModifiedBy as ''Modified By&lt;HIDDEN&gt;''  FROM RptGetCommCellGroups(&lt;loginUserId&gt;)" />')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="SELECT GroupId AS ''GroupId&lt;DONOTSHOW&gt;'',  GroupName AS ''Group Name&lt;CommCellGroup&gt;'', GroupDescription AS ''Group Description&lt;DONOTSHOW&gt;'', CommCellCount as ''Number of CommCells'', ActiveClients as ''Active Clients'', SLA as ''SLA (%)'',  GroupCreatedBy as ''Created By&lt;HIDDEN&gt;'',  GroupModifiedBy as ''Modified By&lt;HIDDEN&gt;''  FROM RptGetCommCellGroups(&lt;loginUserId&gt;)" />' WHERE name = 'METRICS_RPTGETCOMMCELLGROUPS_1'

END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETCOMMCELLGROUPS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETCOMMCELLGROUPS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT GroupName, CommCellCount FROM RptGetCommCellGroups(&lt;loginUserId&gt;) WHERE GroupId = @ccGroupId"><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETCOMMCELLINGROUPS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETCOMMCELLINGROUPS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT CommServUniqueId AS [CommServUniqueId&lt;DONOTSHOW&gt;], IncludedInGroup AS [Associate To CommCell Group&lt;AssociateToCommCellGroup&gt;], CommCellID AS [CommCell ID], CommServGUID AS [CommServGUID&lt;DONOTSHOW&gt;], DisplayName AS [Display Name&lt;DONOTSHOW&gt;],  CommCellName AS [CommCell Name], CommServTZ AS [Time Zone] , CommServVersion AS [Version] FROM dbo.RptGetCommCellsInGroup(&lt;loginUserId&gt; , @ccGroupId, @includeDisabledCC) ORDER BY IncludedInGroup DESC, CommCellName"> <parameters name="ccGroupId" dataType="5" /><parameters name="includeDisabledCC" dataType="5" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="SELECT CommServUniqueId AS [CommServUniqueId&lt;DONOTSHOW&gt;], IncludedInGroup AS [Associate To CommCell Group&lt;AssociateToCommCellGroup&gt;], CommCellID AS [CommCell ID], CommServGUID AS [CommServGUID&lt;DONOTSHOW&gt;], DisplayName AS [Display Name&lt;DONOTSHOW&gt;],  CommCellName AS [CommCell Name], CommServTZ AS [Time Zone] , CommServVersion AS [Version] FROM dbo.RptGetCommCellsInGroup(&lt;loginUserId&gt; , @ccGroupId, @includeDisabledCC) ORDER BY IncludedInGroup DESC, CommCellName"> <parameters name="ccGroupId" dataType="5" /><parameters name="includeDisabledCC" dataType="5" /></ReportPlus_OperationProperties>'

	WHERE name = 'METRICS_RPTGETCOMMCELLINGROUPS_1'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETCOMMCELLGROUPS_COUNT')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETCOMMCELLGROUPS_COUNT', '', '<ReportPlus_OperationProperties sqlText="SELECT COUNT(*) AS count FROM RptGetCommCellGroups(&lt;loginUserId&gt;)" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYCONFIG_NAME_VALUE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYCONFIG_NAME_VALUE', '', '<ReportPlus_OperationProperties sqlText="SELECT Name as ''isPrivate'' ,Value as  ''Value'' FROM cf_SurveyConfig WHERE Name = ''isPrivate''" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYCONFIG_VALUE_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYCONFIG_VALUE_1', '', '<ReportPlus_OperationProperties sqlText="SELECT Value FROM cf_SurveyConfig WHERE Name = ''isPrivate''" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYCONFIG_VALUE_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYCONFIG_VALUE_2', '', '<ReportPlus_OperationProperties sqlText="SELECT Value FROM cf_surveyConfig WHERE name LIKE ''ShowCommcellIdInReport''" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_1')

BEGIN
    INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, -1, 0, 5">   <parameters name="commUniId" dataType="5" /> </ReportPlus_OperationProperties>')


END 

ELSE

    UPDATE APP_DATASTATEMENTS

    SET operation = '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, -1, 0, 5">   <parameters name="commUniId" dataType="5" /> </ReportPlus_OperationProperties>'

    WHERE name = 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_1'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_2')

BEGIN
    INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, -1, 0, 6">   <parameters name="commUniId" dataType="5" /> </ReportPlus_OperationProperties>')


END

ELSE

    UPDATE APP_DATASTATEMENTS

    SET operation = '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, -1, 0, 6">   <parameters name="commUniId" dataType="5" /> </ReportPlus_OperationProperties>'

    WHERE name = 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_2'

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_3')

BEGIN
    INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_3', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, @ccGroupId, 0, 0"> <parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

    UPDATE APP_DATASTATEMENTS

    SET operation = '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, @ccGroupId, 0, 0"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>' 

    WHERE name = 'METRICS_RPTGETSERVERHEALTHFUNC_DETAILS_3'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_COMMSERVSURVEYQUERIES_GROUPS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_COMMSERVSURVEYQUERIES_GROUPS', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT g.SurveyGroupId, g.Name FROM cf_CommservSurveyGroupMap AS gM INNER JOIN cf_CommservSurveyQueries AS q ON gM.SurveyId = q.QueryId INNER JOIN dbo.RptGetMetricsQueryFlags(0) F ON Q.QueryId =  F.QueryId AND F.QueryFlags &amp; 4 = 4 INNER JOIN cf_CommservSurveyGroups AS g ON g.SurveyGroupId = gM.GroupId"></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS SET operation = '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT g.SurveyGroupId, g.Name FROM cf_CommservSurveyGroupMap AS gM INNER JOIN cf_CommservSurveyQueries AS q ON gM.SurveyId = q.QueryId INNER JOIN dbo.RptGetMetricsQueryFlags(0) F ON Q.QueryId =  F.QueryId AND F.QueryFlags &amp; 4 = 4 INNER JOIN cf_CommservSurveyGroups AS g ON g.SurveyGroupId = gM.GroupId"></ReportPlus_OperationProperties>' WHERE NAME = 'METRICS_CF_COMMSERVSURVEYQUERIES_GROUPS'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_ALL_ENTRIES')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETSERVERHEALTHFUNC_ALL_ENTRIES', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, @ccGroupId, @isLocal, 10">   <parameters name="commUniId" dataType="5" />   <parameters name="ccGroupId" dataType="5" />   <parameters name="isLocal" dataType="5" /> </ReportPlus_OperationProperties>')


END

ELSE

	UPDATE APP_DATASTATEMENTS SET operation = '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, @ccGroupId, @isLocal, 10">   <parameters name="commUniId" dataType="5" />   <parameters name="ccGroupId" dataType="5" />   <parameters name="isLocal" dataType="5" /> </ReportPlus_OperationProperties>' WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_ALL_ENTRIES'

	IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_COMMSERVSURVEYGROUPS_ID_NAME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_COMMSERVSURVEYGROUPS_ID_NAME', '', '<ReportPlus_OperationProperties sqlText="SELECT SurveyGroupId, Name FROM cf_CommservSurveyGroups ORDER BY SurveyGroupId" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_METRICSLOGGEDINUSERS_SURVEY_CAPABILITY')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_METRICSLOGGEDINUSERS_SURVEY_CAPABILITY', '', '<ReportPlus_OperationProperties sqlText="SELECT surveycapability FROM cf_MetricsLoggedInUsers WITH (NOLOCK) WHERE UserId = &lt;loginUserId&gt;" />')


END		

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADESLA_TOP_SID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADESLA_TOP_SID', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 SurveyResultId FROM cf_SurveyPrePostUpgradeSLA WHERE CommServUniqueId = @commUniId order by SurveyResultId DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADESLA_POSITIVE_DAYS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADESLA_POSITIVE_DAYS', '', '<ReportPlus_OperationProperties sqlText="SELECT nProtectedClients, nUnprotectedClients, nExcludedClients FROM cf_SurveyPrePostUpgradeSLA WHERE CommServUniqueId = @commUniId AND SurveyResultId = @surveyResultIdSLA AND Days = @days"><parameters name="commUniId" dataType="5" /><parameters name="surveyResultIdSLA" dataType="0" /><parameters name="days" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADESLA_NEGATIVE_DAYS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADESLA_NEGATIVE_DAYS', '', '<ReportPlus_OperationProperties sqlText="SELECT nProtectedClients, nUnprotectedClients, nExcludedClients FROM cf_SurveyPrePostUpgradeSLA WHERE CommServUniqueId = @commUniId AND SurveyResultId = @surveyResultIdSLA AND Days = -@days"><parameters name="commUniId" dataType="5" /><parameters name="surveyResultIdSLA" dataType="0" /><parameters name="days" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_TOP_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_TOP_1', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId order by SurveyResultId DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_RESULT_ID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_RESULT_ID', '', '<ReportPlus_OperationProperties sqlText="IF (SELECT COUNT(*) FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC BETWEEN @upgradedate AND DATEADD(day,22, @upgradedate)) = 0 SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC &gt; DATEADD(day,22,@upgradedate) ELSE SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC BETWEEN @upgradedate AND DATEADD(day,22,@upgradedate) order by LogDateUTC DESC">  <parameters name="commUniId" dataType="5" />  <parameters name="upgradedate" dataType="0" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="IF (SELECT COUNT(*) FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC BETWEEN @upgradedate AND DATEADD(day,22, @upgradedate)) = 0 SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC &gt; DATEADD(day,22,@upgradedate) ELSE SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC BETWEEN @upgradedate AND DATEADD(day,22,@upgradedate) order by LogDateUTC DESC">  <parameters name="commUniId" dataType="5" />  <parameters name="upgradedate" dataType="0" /></ReportPlus_OperationProperties>' WHERE name = 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_RESULT_ID'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT MAName, IndexRestoreJobCount, TotalCapacityMB/1024.0 TotalCapacityGB, DiskUsageMB/1024.0 DiskUsageGB, FreeDiskSpaceMB/1024.0 FreeDiskSpaceGB  FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND UpgradeType = 1 AND Days = @days AND SurveyResultId = (SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND LogDateUTC > @upgradedate)"><parameters name="commUniId" dataType="5" /><parameters name="days" dataType="0" /><parameters name="upgradedate" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEINDEXRESTORESTATS_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT MAName, IndexRestoreJobCount, TotalCapacityMB/1024.0 TotalCapacityGB, DiskUsageMB/1024.0 DiskUsageGB, FreeDiskSpaceMB/1024.0 FreeDiskSpaceGB FROM cf_SurveyUpgradeIndexRestoreStats WHERE CommServUniqueId = @commUniId AND UpgradeType = @upgradeType AND Days = @days AND SurveyResultId = @surveyResultId"><parameters name="commUniId" dataType="5" /><parameters name="upgradeType" dataType="0" /><parameters name="days" dataType="0" /><parameters name="surveyResultId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADECHECK_TOP_RESULT_ID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADECHECK_TOP_RESULT_ID', '', '<ReportPlus_OperationProperties sqlText="SELECT top 1 SurveyResultId FROM cf_SurveyUpgradeCheck WHERE CommServUniqueId = @commUniId order by SurveyResultId DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADECHECK_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADECHECK_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT SUM(SuccessfulJobs) Completed, SUM([CWEJobs]) AS [CWEJobs], SUM(FailedJobs) Failed, SUM(KilledJobs) Killed  FROM cf_SurveyUpgradeCheck WHERE CommServUniqueId = @commUniId AND UpgradeType = 1 AND SurveyResultId = @surveyResultId AND Days = @days  group by CommServUniqueId"><parameters name="commUniId" dataType="5" /><parameters name="surveyResultId" dataType="5" /><parameters name="days" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADECHECK_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADECHECK_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT SUM(SuccessfulJobs) Completed, SUM([CWEJobs]) AS [CWEJobs], SUM(FailedJobs) Failed, SUM(KilledJobs) Killed  FROM cf_SurveyUpgradeCheck WHERE CommServUniqueId = @commUniId AND UpgradeType = 2 AND SurveyResultId = @surveyResultId AND Days = @days  group by CommServUniqueId"><parameters name="commUniId" dataType="5" /><parameters name="surveyResultId" dataType="5" /><parameters name="days" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT weekNo,LogDate,AgentType,CAST(SUM(FullAppSize)/(1024.0*1024.0*1024.0) AS DECIMAL(10,2)) AS FullAppSizeGB FROM cf_Survey91ProtectedDataPerAgent6WeekInfo WHERE SurveyResultId=(SELECT MAX(SurveyResultId) FROM cf_Survey91ProtectedDataPerAgent6WeekInfo WHERE CommServUniqueId = @commUniId) AND CommServUniqueId=@commUniId group by LogDate,weekNo,AgentType order by weekNo DESC,AgentType asc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT AgentType,AVG(FullAppSize) As ApplicationSize FROM cf_Survey91ProtectedDataPerAgent6WeekInfo WHERE SurveyResultId=(SELECT MAX(SurveyResultId) FROM cf_Survey91ProtectedDataPerAgent6WeekInfo WHERE CommServUniqueId =@commUniId ) AND CommServUniqueId =@commUniId group by AgentType order by  AgentType asc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_3')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_3', '', '<ReportPlus_OperationProperties sqlText="SELECT csInfo.CommServUniqueId AS ''CommServe UniqueId'',csInfo.AgentType AS ''Agent'',  SUM(csInfo.FullJobCount) AS ''Job Count'' FROM cf_Survey91ProtectedDataPerAgent6WeekInfo AS csInfo WITH (NOLOCK) INNER JOIN dbo.cf_SurveyResultFunc(91, @commUniId , 1, NULL, NULL,&lt;loginUserId&gt;) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId AND resultView.LogDateUTC = csInfo.LogDateUTC AND resultView.CommServUniqueId = csInfo.CommServUniqueId AND resultView.SureyResultFlags = 1 AND csInfo.CommServUniqueId = @commUniId AND csInfo.weekNo =7 group by csInfo.CommServUniqueId,csinfo.AgentType order by csInfo.AgentType"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEHISTORY_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEHISTORY_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT Releaseid, InstallTime, CONVERT(VARCHAR(11),InstallTime,6) StrInstallTime FROM cf_SurveyUpgradeHistory WHERE  surveyresultid = (SELECT top 1 surveyresultid FROM cf_SurveyUpgradeHistory WHERE CommServUniqueId = @commUniId order by logdateutc DESC)"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEY81COMMCELLCLIENTMAVERSION_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEY81COMMCELLCLIENTMAVERSION_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT Distinct Nodes_TypeofNode,Nodes_Status,Nodes_Count FROM cf_Survey81CommCellClientMAVersion WHERE CommServUniqueId = @commUniId AND SurveyResultId= (SELECT MAX(SurveyResultId) FROM cf_Survey81CommCellClientMAVersion WHERE CommServUniqueId=@commUniId) order by Nodes_TypeofNode asc,Nodes_Status DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEY78TBLSIDBSTOREANDBASELINESIZE_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEY78TBLSIDBSTOREANDBASELINESIZE_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 5 SPName,SIDBStoreAliasName,StoragePolicyCpy,totalAppSize AS totalAppSize, sizeOnMedia AS sizeOnMedia, BaselineSize AS BaselineSize FROM [cf_Survey78TblSIDBStoreAndBaselineSize] WHERE CommServUniqueId=@commUniId AND SurveyResultId = (SELECT MAX(SurveyResultId) FROM cf_Survey78TblSIDBStoreAndBaselineSize WHERE CommServUniqueId=@commUniId ) ORDER BY BaselineSize DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEREADINESS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEREADINESS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(11),LogDateUTC,6) LogDate, CheckName, Status, Comments, DBName FROM cf_SurveyUpgradeReadiness WHERE commservuniqueid = @commUniId AND DBName = @dbname"><parameters name="commUniId" dataType="5" /><parameters name="dbname" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYUPGRADEREADINESS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYUPGRADEREADINESS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(11),LogDateUTC,6) LogDate, CheckName, Status, Comments, DBName, '''' AS Comment FROM cf_SurveyUpgradeReadiness WHERE commservuniqueid = @commUniId AND DBName = @dbname  AND CheckName not in (''tblDBUAll'',''tblScriptDBUAll_V2'',''tblScriptDBUAll'',''SIMTableDrop'',''CheckSpacesInClientNames'',''SIMTmpTblForDepPkgCheck'',''SIMVSAInstanceCheck_CS'')"><parameters name="commUniId" dataType="5" /><parameters name="dbname" dataType="0" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation = '<ReportPlus_OperationProperties sqlText="SELECT CONVERT(VARCHAR(11),LogDateUTC,6) LogDate, CheckName, Status, Comments, DBName, '''' AS Comment FROM cf_SurveyUpgradeReadiness WHERE commservuniqueid = @commUniId AND DBName = @dbname  AND CheckName not in (''tblDBUAll'',''tblScriptDBUAll_V2'',''tblScriptDBUAll'',''SIMTableDrop'',''CheckSpacesInClientNames'',''SIMTmpTblForDepPkgCheck'',''SIMVSAInstanceCheck_CS'')"><parameters name="commUniId" dataType="5" /><parameters name="dbname" dataType="0" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_CF_SURVEYUPGRADEREADINESS_2'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEY77CLIENTDETAILS_CF_SURVEYRESULTFUNC')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEY77CLIENTDETAILS_CF_SURVEYRESULTFUNC', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT clientName, Type FROM cf_SurveyClient WHERE CommservUniqueId = @commUniId AND Deleted = 0 AND type IN ( @clientTypes ) @filterClause UNION (SELECT ClientGroupName AS clientName, 0 AS Type FROM cf_surveyClientGroup WHERE CommservUniqueId = @commUniId)"><parameters name="commUniId" dataType="5" /><parameters name="clientTypes" dataType="0" /><parameters name="filterClause" dataType="0" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation = '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT clientName, Type FROM cf_SurveyClient WHERE CommservUniqueId = @commUniId AND Deleted = 0 AND type IN ( @clientTypes ) @filterClause UNION (SELECT ClientGroupName AS clientName, 0 AS Type FROM cf_surveyClientGroup WHERE CommservUniqueId = @commUniId)"><parameters name="commUniId" dataType="5" /><parameters name="clientTypes" dataType="0" /><parameters name="filterClause" dataType="0" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'METRICS_CF_SURVEY77CLIENTDETAILS_CF_SURVEYRESULTFUNC'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_GETAVGBKPTHROUGHPUT_CC_AVG')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_GETAVGBKPTHROUGHPUT_CC_AVG', '', '<ReportPlus_OperationProperties sqlText="SELECT dbo.Getavgbkpthroughput(@commUniId, 1, 2, &lt;loginUserId&gt;, @ccGroupId) AS CCAvg"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_MAX_STATUS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_RPTGETSERVERHEALTHFUNC_MAX_STATUS', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, @ccGroupId, 0, 4">   <parameters name="commUniId" dataType="5" />   <parameters name="ccGroupId" dataType="5" /> </ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, @ccGroupId, 0, 4">   <parameters name="commUniId" dataType="5" />   <parameters name="ccGroupId" dataType="5" /> </ReportPlus_OperationProperties>' WHERE NAME = 'METRICS_RPTGETSERVERHEALTHFUNC_MAX_STATUS'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GLDB_REQUESTTYPE_ID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@gldbDataSetId, 'GLDB_REQUESTTYPE_ID', '', '<ReportPlus_OperationProperties sqlText="SELECT requestTypeId AS id FROM RequestType WHERE RequestType LIKE @requestType"><parameters name="requestType" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_COMMCELLIDNAMEMAP_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_COMMCELLIDNAMEMAP_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="Select UPPER(sys.fn_varbintohexstr(CONVERT(varBINARY(8),CAST(CommCellID AS INT)))) AS CommCellId,CASE WHEN CustomerName LIKE '''' THEN CommServName ELSE CustomerName END AS CustomerName FROM cf_CommcellIdNameMap WHERE ID=@commUniId"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYCSDETAILSINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYCSDETAILSINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 CommServVersion FROM dbo.cf_SurveyCSDetailsInfo where CommServUniqueId=@commUniId order by LogDate desc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYUPDATEINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYUPDATEINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT Top 1 ISNULL(CSAddUpdates,''None'') AS CSAddUpdates FROM dbo.cf_SurveyUpdateInfo WHERE CommServUniqueId=@commUniId order by LogDate desc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYRESULTVIEW_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYRESULTVIEW_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="Select Top 1 CommServVersion from dbo.cf_SurveyResultView where SurveyID = 12 and CommServUniqueId=@commUniId order by LogDateUTC desc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYUPDATECACHEINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYUPDATECACHEINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="IF ((Select  MAX(CacheSP) FROM cf_SurveyUpdateCacheInfo where CommServUniqueId =@commUniId and SurveyResultId = (select MAX(SurveyResultId) from cf_SurveyUpdateCacheInfo where CommServUniqueId=@commUniId)) &lt;= @innerResult) begin select ''None'' AS CacheSP end else begin Select MAX(CacheSP) AS CacheSP FROM cf_SurveyUpdateCacheInfo where CommServUniqueId =@commUniId and SurveyResultId = (select MAX(SurveyResultId) from cf_SurveyUpdateCacheInfo where CommServUniqueId=@commUniId) end"><parameters name="commUniId" dataType="5" /><parameters name="innerResult" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYUPDATECACHEINFO_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYUPDATECACHEINFO_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT MAX(CacheSP) AS ''CacheSP'' FROM cf_SurveyUpdateCacheInfo WHERE CommServUniqueId =@commUniId AND SurveyResultId = (SELECT MAX(SurveyResultId) FROM cf_SurveyUpdateCacheInfo WHERE CommServUniqueId=@commUniId)"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYDRBKPCONFIGURATION_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYDRBKPCONFIGURATION_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="IF EXISTS (SELECT FullJobsToRetain, IsUingNetworkPath FROM cf_SurveyDRBkpConfiguration csInfo INNER JOIN dbo.cf_SurveyResultFuncV1(31, @commUniId, 1, null, null,&lt;loginUserId&gt;,-1) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId) BEGIN SELECT TOP 1 ''Currently this phase is being saved at the ''+CASE (IsUingNetworkPath) WHEN ''false'' THEN ''Local drive'' ELSE ''UNC'' END + '' path.  It is currently configured to retain the last '' + CAST(FullJobsToRetain AS VARCHAR(10)) + '' backups sets'' as DRBkpConfig FROM cf_SurveyDRBkpConfiguration csInfo INNER JOIN dbo.cf_SurveyResultFuncV1(31, @commUniId, 1, null, null, &lt;loginUserId&gt;,-1) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId END ELSE BEGIN SELECT ''DR Backup is not currently configured'' as DRBkpConfig END "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYDRBKPCONFIGURATION_TOP_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYDRBKPCONFIGURATION_TOP_1', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 FullJobsToRetain, IsUingNetworkPath FROM cf_SurveyDRBkpConfiguration WHERE CommServUniqueId=@commUniId ORDER BY LogDate DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYDRSTATS_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYDRSTATS_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="IF ISNULL((SELECT  TOP 1 LastSuccessfulDRTime FROM cf_SurveyDRStats csInfo INNER JOIN dbo.cf_SurveyResultFuncV1(19, @commUniId, 1, null, null,&lt;loginUserId&gt;,-1) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId),0) &lt;&gt; 0 BEGIN SELECT ''The CommVault last successful DR backup occured on '' + CAST(CONVERT(VARCHAR, (dbo.UTCToLocalDateTimeConversion((SELECT TOP 1 DATEADD(second,LastSuccessfulDRTime, CAST(''1970-01-01 00:00:00'' AS DATETIME)) FROM cf_SurveyDRStats csInfo INNER JOIN dbo.cf_SurveyResultFuncV1(19, @commUniId, 1, null, null, &lt;loginUserId&gt;,-1) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId), (SELECT CommServTZ FROM cf_CommcellIdNameMap WHERE ID=@commUniId))),100) AS varchar) AS LastSuccessfulDRBkp END ELSE BEGIN SELECT ''There has been no successful DR jobs so far'' AS LastSuccessfulDRBkp END "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYDRSTATS_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYDRSTATS_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 LastSuccessfulDRTime, CAST(CONVERT(VARCHAR, (dbo.UTCToLocalDateTimeConversion(DATEADD(second,LastSuccessfulDRTime, CAST(''1970-01-01 00:00:00'' AS DATETIME)),resultView.CommServTimeZone)),100) AS varchar) AS NeededTime FROM cf_SurveyDRStats csInfo INNER JOIN dbo.cf_SurveyResultFuncV1(19, @commUniId, 1, null, null, &lt;loginUserId&gt;, -1) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYPROTECTEDDATAPERAGENT_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYPROTECTEDDATAPERAGENT_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT distinct (csInfo.AgentType)  AS ''Agent'' FROM cf_SurveyProtectedDataPerAgent AS csInfo WITH (NOLOCK) INNER JOIN dbo.cf_SurveyResultFunc(54, @commUniId, 1, NULL, NULL, &lt;loginUserId&gt;) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId AND resultView.LogDateUTC = csInfo.LogDateUTC AND resultView.CommServUniqueId = csInfo.CommServUniqueId AND resultView.SureyResultFlags = 1 AND csInfo.CommServUniqueId = @commUniId"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYPROTECTEDDATAPERAGENT_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYPROTECTEDDATAPERAGENT_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT CAST(ROUND(ISNULL((SUM(csInfo.ApplicationSizeMB)/1024.0),0),2) AS DECIMAL(32,2)) AS ''ApplicationSize'' FROM cf_SurveyProtectedDataPerAgent AS csInfo WITH (NOLOCK) INNER JOIN dbo.cf_SurveyResultFunc(54, @commUniId, 1, null, null, &lt;loginUserId&gt;) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId AND resultView.LogDateUTC = csInfo.LogDateUTC AND resultView.CommServUniqueId = csInfo.CommServUniqueId AND resultView.SureyResultFlags = 1 AND csInfo.CommServUniqueId = @commUniId "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEY78TBLSIDBSTOREANDBASELINESIZE_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEY78TBLSIDBSTOREANDBASELINESIZE_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 5 SPName,SIDBStoreAliasName,StoragePolicyCpy,CAST(ROUND((totalAppSize/(1024.0*1024.0*1024.0)),2) AS DECIMAL(10,2)) AS totalAppSize,CAST(ROUND((sizeOnMedia/(1024.0*1024.0*1024.0)),2) AS DECIMAL(10,2)) AS sizeOnMedia ,CAST(ROUND((BaselineSize/(1024.0*1024.0*1024.0)),2) AS DECIMAL(10,2)) AS BaselineSize FROM [cf_Survey78TblSIDBStoreAndBaselineSize] where CommServUniqueId= @commUniId AND SurveyResultId = (SELECT MAX(SurveyResultId) from cf_Survey78TblSIDBStoreAndBaselineSize where CommServUniqueId=@commUniId ) ORDER BY BaselineSize DESC"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_RPTGETSERVERHEALTHFUNC_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_RPTGETSERVERHEALTHFUNC_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, -1, 0, 8">   <parameters name="commUniId" dataType="5" /> </ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS

	SET operation = '<ReportPlus_OperationProperties sqlText="EXEC RptGetserverHealth @commUniId,  &lt;loginUserId&gt;, -1, 0, 8">   <parameters name="commUniId" dataType="5" /> </ReportPlus_OperationProperties>' 

	WHERE name = 'HEALTH_DOCX_RPTGETSERVERHEALTHFUNC_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEY81COMMCELLCLIENTMAVERSION_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEY81COMMCELLCLIENTMAVERSION_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="Select Distinct Nodes_TypeofNode,Nodes_Status,Nodes_Count from cf_Survey81CommCellClientMAVersion where CommServUniqueId=@commUniId AND SurveyResultId= (SELECT MAX(SurveyResultId) from cf_Survey81CommCellClientMAVersion where CommServUniqueId=@commUniId) order by Nodes_TypeofNode asc,Nodes_Status desc "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT csInfo.CommServUniqueId AS ''CommServe UniqueId'',csInfo.AgentType AS ''Agent'', SUM(csInfo.FullJobCount) AS ''Job Count'' FROM cf_Survey91ProtectedDataPerAgent6WeekInfo AS csInfo WITH (NOLOCK) INNER JOIN dbo.cf_SurveyResultFunc(91, @commUniId , 1, NULL, NULL, &lt;loginUserId&gt;) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId AND resultView.LogDateUTC = csInfo.LogDateUTC AND resultView.CommServUniqueId = csInfo.CommServUniqueId AND resultView.SureyResultFlags = 1 AND csInfo.CommServUniqueId = @commUniId AND csInfo.weekNo =7 group by csInfo.CommServUniqueId,csinfo.AgentType "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEY91PROTECTEDDATAPERAGENT6WEEKINFO_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="Select AgentType,AVG(FullAppSize) As ApplicationSize from cf_Survey91ProtectedDataPerAgent6WeekInfo where SurveyResultId=(SELECT MAX(SurveyResultId) FROM cf_Survey91ProtectedDataPerAgent6WeekInfo WHERE CommServUniqueId =@commUniId ) AND CommServUniqueId =@commUniId group by AgentType order by  AgentType asc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYUPDATEINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYUPDATEINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 CSDBSP,CSAddUpdates FROM dbo.cf_SurveyUpdateInfo WHERE CommServUniqueId=@commUniId order by LogDate desc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_CF_SURVEYRESULTVIEW_VERSION_LOGDATE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_CF_SURVEYRESULTVIEW_VERSION_LOGDATE', '', '<ReportPlus_OperationProperties sqlText="Select Top 1 CommServVersion,LogDateUTC from dbo.cf_SurveyResultView where SurveyID = 12 and CommServUniqueId=@commUniId order by LogDateUTC desc"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_PROTECTEDDATAPERAGENT_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_PROTECTEDDATAPERAGENT_1', '', '<ReportPlus_OperationProperties sqlText="SELECT csInfo.AgentType AS ''Agent Type'', A.displayName AS ''Agent Subtype'', SUM(csInfo.FullJobCount) AS ''Full Backups (Total Jobs)'' FROM cf_Survey91ProtectedDataPerAgent6WeekInfo AS csInfo WITH (NOLOCK) INNER JOIN dbo.cf_SurveyResultFunc(91, @commUniId , 1, NULL, NULL, &lt;loginUserId&gt;) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId AND resultView.LogDateUTC = csInfo.LogDateUTC AND resultView.CommServUniqueId = csInfo.CommServUniqueId AND resultView.SureyResultFlags = 1 AND csInfo.CommServUniqueId = @commUniId AND csInfo.weekNo =7 INNER JOIN cf_SurveyAgentType A WITH(NOLOCK) ON csInfo.AgentTypeId = A.id group by csInfo.CommServUniqueId, csinfo.AgentType, A.displayName ORDER BY csInfo.AgentType "><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_PROTECTEDDATAPERAGENT_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_PROTECTEDDATAPERAGENT_2', '', '<ReportPlus_OperationProperties sqlText="SELECT AgentType AS ''Agent Type'', AgentSubType AS ''Agent Subtype'', [7] AS ''Week 6'', [6] AS ''Week 5'', [5] AS ''Week 4'', [4] AS ''Week 3'', [3] AS ''Week 2'', [2] AS ''Week 1'' FROM (SELECT csInfo.weekNo,csInfo.AgentType AS ''AgentType'',A.displayName AS ''AgentSubType'',SUM(csInfo.FullAppSize)/(1024.0*1024.0*1024.0) AS FullAppSize FROM cf_Survey91ProtectedDataPerAgent6WeekInfo AS csInfo WITH (NOLOCK) INNER JOIN dbo.cf_SurveyResultFuncV1(91, @commUniId, 1, null, null,&lt;loginUserId&gt;,-1) AS resultView ON resultView.SurverResultId = csInfo.SurveyResultId AND resultView.LogDateUTC = csInfo.LogDateUTC AND resultView.CommServUniqueId = csInfo.CommServUniqueId AND resultView.SureyResultFlags = 1 AND csInfo.CommServUniqueId = @commUniId INNER JOIN cf_SurveyAgentType A WITH (NOLOCK) ON csInfo.AgentTypeId = A.id WHERE weekNo &gt; 1 GROUP BY csInfo.AgentType,csInfo.weekNo,csInfo.endDate, A.displayName) AS Source PIVOT (SUM(FullAppSize) FOR weekNo IN ([2], [3], [4], [5], [6], [7])) AS pivoted ORDER BY AgentType, AgentSubType"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'HEALTH_DOCX_PROTECTEDDATAPERAGENT_3')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'HEALTH_DOCX_PROTECTEDDATAPERAGENT_3', '', '<ReportPlus_OperationProperties sqlText="Select AgentType AS ''Agent Type'', A.displayName AS ''Agent Subtype'', AVG(FullAppSize) As ''Application Size'' from cf_Survey91ProtectedDataPerAgent6WeekInfo csInfo WITH (NOLOCK) INNER JOIN cf_SurveyAgentType A WITH(NOLOCK) ON csInfo.AgentTypeId = A.id where SurveyResultId=(SELECT MAX(SurveyResultId) FROM cf_Survey91ProtectedDataPerAgent6WeekInfo WHERE CommServUniqueId =@commUniId ) AND CommServUniqueId =@commUniId group by AgentType, A.displayName order by  AgentType, A.displayName"><parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_DATACENTER_ID_NAME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_DATACENTER_ID_NAME', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT DataCenterId, DataCenterName FROM @table"><parameters name="table" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_RESTOREJOBINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_RESTOREJOBINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT JobId AS [Job], ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], JobStartDateTime AS [Start Time&lt;dateTimeRenderer&gt;], [JobEndDateTime] AS [Finish Time&lt;dateTimeRenderer&gt;], FilesSkipped AS [Files Skipped], restoreJobDurationMinutes AS [Job Duration(Minutes)], JobStatus AS [Job Status] FROM DBO.[ms_RestoreJobInfo](@custId, @dcId, @serverId, @lastNdays, @startDate, @endDate, @jobStatus)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="serverId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /><parameters name="jobStatus" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT JobId AS [Job], ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], JobStartDateTime AS [Start Time&lt;dateTimeRenderer&gt;], [JobEndDateTime] AS [Finish Time&lt;dateTimeRenderer&gt;], FilesSkipped AS [Files Skipped], restoreJobDurationMinutes AS [Job Duration(Minutes)], JobStatus AS [Job Status] FROM DBO.[ms_RestoreJobInfo](@custId, @dcId, @serverId, @lastNdays, @startDate, @endDate, @jobStatus)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="serverId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /><parameters name="jobStatus" dataType="5" /></ReportPlus_OperationProperties>' WHERE name='MSDB_MS_RESTOREJOBINFO_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_BACKUPJOBINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_BACKUPJOBINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT JobId AS [Job], ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], BackupContent AS [Target], JobStartDateTime AS [Start Time&lt;dateTimeRenderer&gt;], [JobEndDateTime] AS [Finish Time&lt;dateTimeRenderer&gt;], BackupLevel AS [Level], TotBackupVolGB AS [Vol GB], FilesSkipped AS [Files Skipped], Retention AS [Days Retained], JobStatus AS [Job Status] FROM DBO.[ms_BackupJobInfo](@custId, @dcId, @serverId, @lastNdays, @startDate, @endDate, @jobStatus)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="serverId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /><parameters name="jobStatus" dataType="5" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT JobId AS [Job], ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], BackupContent AS [Target], JobStartDateTime AS [Start Time&lt;dateTimeRenderer&gt;], [JobEndDateTime] AS [Finish Time&lt;dateTimeRenderer&gt;], BackupLevel AS [Level], TotBackupVolGB AS [Vol GB], FilesSkipped AS [Files Skipped], Retention AS [Days Retained], JobStatus AS [Job Status] FROM DBO.[ms_BackupJobInfo](@custId, @dcId, @serverId, @lastNdays, @startDate, @endDate, @jobStatus)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="serverId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /><parameters name="jobStatus" dataType="5" /></ReportPlus_OperationProperties>' WHERE name='MSDB_MS_BACKUPJOBINFO_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_PROPERTYDIMENSION_ID_NAME')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_PROPERTYDIMENSION_ID_NAME', '', '<ReportPlus_OperationProperties sqlText="SELECT DISTINCT PropertyDimensionId, PropertyDimensionName FROM @table"><parameters name="table" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_CUSTOMERRESTOREINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_CUSTOMERRESTOREINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomer&gt;], TotServer AS [Server Count], TotRestores AS [Job Count], SucRestores AS [Success Restores], SLAPerc AS ''%SLA'' FROM DBO.[ms_CustomerRestoreInfo](@custId,@dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomer&gt;], TotServer AS [Server Count], TotRestores AS [Job Count], SucRestores AS [Success Restores], SLAPerc AS ''%SLA'' FROM DBO.[ms_CustomerRestoreInfo](@custId,@dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>' where name='MSDB_MS_CUSTOMERRESTOREINFO_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_CUSTOMERBACKUPINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_CUSTOMERBACKUPINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomer&gt;], TotServer AS [Server Count], TotBackups AS [Job Count], SucBackups AS [Successful Backups], FailBackups AS [Failed Backups], OtherBackups AS [Other Backups], SLAPerc AS ''%SLA'', TotBackupVolGB AS [All Backups(GB)], ShortTermBackupVolGB AS [Short Term(GB) &lt; 91D], LongTermBackupVolGB AS [Long Term(GB) > 90D] FROM DBO.[ms_CustomerBackupInfo](@custId, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomer&gt;], TotServer AS [Server Count], TotBackups AS [Job Count], SucBackups AS [Successful Backups], FailBackups AS [Failed Backups], OtherBackups AS [Other Backups], SLAPerc AS ''%SLA'', TotBackupVolGB AS [All Backups(GB)], ShortTermBackupVolGB AS [Short Term(GB) &lt; 91D], LongTermBackupVolGB AS [Long Term(GB) > 90D] FROM DBO.[ms_CustomerBackupInfo](@custId, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>' where name='MSDB_MS_CUSTOMERBACKUPINFO_DETAILS_1'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_CUSTOMERRESTOREINFO_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_CUSTOMERRESTOREINFO_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT TotServer AS [Server Count], TotRestores AS [Job Count], SucRestores AS [Success Restores], SLAPerc AS ''%SLA'' FROM DBO.[ms_CustomerRestoreInfo](@cid, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="cid" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT TotServer AS [Server Count], TotRestores AS [Job Count], SucRestores AS [Success Restores], SLAPerc AS ''%SLA'' FROM DBO.[ms_CustomerRestoreInfo](@cid, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="cid" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>' where name='MSDB_MS_CUSTOMERRESTOREINFO_DETAILS_2'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_CUSTOMERBACKUPINFO_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_CUSTOMERBACKUPINFO_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT TotServer AS [Server Count], TotBackups AS [Job Count], SucBackups AS [Successful Backups], FailBackups AS [Failed Backups], OtherBackups AS [Other Backups], SLAPerc AS ''%SLA'', TotBackupVolGB AS [All Backups(GB)], ShortTermBackupVolGB AS [Short Term(GB) &lt; 91D], LongTermBackupVolGB AS [Long Term(GB) > 90D] FROM DBO.[ms_CustomerBackupInfo](@cid, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="cid" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT TotServer AS [Server Count], TotBackups AS [Job Count], SucBackups AS [Successful Backups], FailBackups AS [Failed Backups], OtherBackups AS [Other Backups],SLAPerc AS ''%SLA'', TotBackupVolGB AS [All Backups(GB)], ShortTermBackupVolGB AS [Short Term(GB) &lt; 91D], LongTermBackupVolGB AS [Long Term(GB) > 90D] FROM DBO.[ms_CustomerBackupInfo](@cid, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="cid" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>' where name='MSDB_MS_CUSTOMERBACKUPINFO_DETAILS_2'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_SERVERRESTOREINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_SERVERRESTOREINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server&lt;MSServer&gt;], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomerJobs&gt;], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], TotRestores AS [Job Count], SucRestores AS [Success Restores], SLAPerc AS ''%SLA'' FROM DBO.[ms_ServerRestoreInfo](@custId, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server&lt;MSServer&gt;], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomerJobs&gt;], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], TotRestores AS [Job Count], SucRestores AS [Success Restores], SLAPerc AS ''%SLA'' FROM DBO.[ms_ServerRestoreInfo](@custId, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>' WHERE name='MSDB_MS_SERVERRESTOREINFO_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_MS_SERVERBACKUPINFO_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_MS_SERVERBACKUPINFO_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server&lt;MSServer&gt;], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomerJobs&gt;], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], TotBackups AS [Job Count], SucBackups AS [Successful Backups], FailBackups AS [Failed Backups], OtherBackups AS [Other Backups], SLAPerc AS ''%SLA'', TotBackupVolGB AS [All Backup(GB)], ShortTermBackupVolGB AS [Short Term(GB) &lt; 91D], LongTermBackupVolGB AS [Long Term(GB) &gt; 90D] FROM DBO.[ms_ServerBackupInfo](@custId, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server&lt;MSServer&gt;], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension&lt;MSCustomerJobs&gt;], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], TotBackups AS [Job Count], SucBackups AS [Successful Backups], FailBackups AS [Failed Backups], OtherBackups AS [Other Backups], SLAPerc AS ''%SLA'', TotBackupVolGB AS [All Backup(GB)], ShortTermBackupVolGB AS [Short Term(GB) &lt; 91D], LongTermBackupVolGB AS [Long Term(GB) &gt; 90D] FROM DBO.[ms_ServerBackupInfo](@custId, @dcId, @lastNdays, @startDate, @endDate)"><parameters name="custId" dataType="5" /><parameters name="dcId" dataType="5" /><parameters name="lastNdays" dataType="5" /><parameters name="startDate" dataType="2" /><parameters name="endDate" dataType="2" /></ReportPlus_OperationProperties>' WHERE name='MSDB_MS_SERVERBACKUPINFO_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_DYN_SP_DETAILS_1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_DYN_SP_DETAILS_1', '', '<ReportPlus_OperationProperties sqlText="SELECT DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS ''DC'', TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success&lt;MSSuccessJobs&gt;'', Fail AS ''Fail&lt;MSFailedJobs&gt;'', Rate AS ''%Rate&lt;MSJobsRate&gt;'' FROM DBO.[@spName](@dcId, @startDate, NULL)"><parameters name="spName" dataType="0" /><parameters name="dcId" dataType="5" /><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END	

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS ''DC'', TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success&lt;MSSuccessJobs&gt;'', Fail AS ''Fail&lt;MSFailedJobs&gt;'', Rate AS ''%Rate&lt;MSJobsRate&gt;'' FROM DBO.[@spName](@dcId, @startDate, NULL)"><parameters name="spName" dataType="0" /><parameters name="dcId" dataType="5" /><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>' WHERE name='MSDB_DYN_SP_DETAILS_1'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_DYN_SP_DETAILS_2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_DYN_SP_DETAILS_2', '', '<ReportPlus_OperationProperties sqlText="SELECT TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success'', Fail AS ''Fail'', Rate AS ''%Rate'' FROM DBO.[@spName](-1, @startDate, NULL)"><parameters name="spName" dataType="0" /><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation='<ReportPlus_OperationProperties sqlText="SELECT TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success'', Fail AS ''Fail'', Rate AS ''%Rate'' FROM DBO.[@spName](-1, @startDate, NULL)"><parameters name="spName" dataType="0" /><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>' WHERE name='MSDB_DYN_SP_DETAILS_2'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_COMMCELLDETAILS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'GATHERLOG_COMMCELLDETAILS', '', '<ReportPlus_OperationProperties sqlText="select csinfo.ID, csinfo.CommServName as commcellname, case csinfo.commcellsurveyservices &amp; POWER(2,6) when 0 then ''False'' else ''True'' end as IsChecked, case csinfo.commcellsurveyservices &amp; POWER(2,5) when 0 then ''False'' else ''True'' end as IsChargebackChecked, csinfo.CommCellID, csinfo.CustomerName as customername, csinfo.commcellsurveyservices as enabledservices, csinfo.commservversion as version, csinfo.CommServGUID, CASE WHEN sr.LogDateUTC &lt; GETUTCDATE() THEN DATEDIFF(HH, ISNULL(sr.LogDateUTC, ''1970-01-01 00:00:00''),GETUTCDATE()) ELSE -1 END as hourssincelastupdate  from cf_CommcellIdNameMap csinfo WITH (nolock) INNER JOIN dbo.cf_SurveyResultFuncV1(2,  @uniqID, 1, NULL, NULL, &lt;loginUserId&gt;, -1) AS sr  ON sr.CommServUniqueId = csinfo.ID where csinfo.ID=@uniqID">


	<parameters name="uniqID" dataType="0" />

	</ReportPlus_OperationProperties>')

END

ELSE

BEGIN

	UPDATE app_datastatements set operation='<ReportPlus_OperationProperties sqlText="select csinfo.ID, csinfo.CommServName as commcellname, case csinfo.commcellsurveyservices &amp; POWER(2,6) when 0 then ''False'' else ''True'' end as IsChecked, case csinfo.commcellsurveyservices &amp; POWER(2,5) when 0 then ''False'' else ''True'' end as IsChargebackChecked, csinfo.CommCellID, csinfo.CustomerName as customername, csinfo.commcellsurveyservices as enabledservices, csinfo.commservversion as version, csinfo.CommServGUID, CASE WHEN sr.LogDateUTC &lt; GETUTCDATE() THEN DATEDIFF(HH, ISNULL(sr.LogDateUTC, ''1970-01-01 00:00:00''),GETUTCDATE()) ELSE -1 END as hourssincelastupdate  from cf_CommcellIdNameMap csinfo WITH (nolock) INNER JOIN dbo.cf_SurveyResultFuncV1(2,  @uniqID, 1, NULL, NULL, &lt;loginUserId&gt;, -1) AS sr  ON sr.CommServUniqueId = csinfo.ID where csinfo.ID=@uniqID">

	<parameters name="uniqID" dataType="0" />

	</ReportPlus_OperationProperties>' where name like 'GATHERLOG_COMMCELLDETAILS'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_COMMCELL_CLIENTS_LIST')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'GATHERLOG_COMMCELL_CLIENTS_LIST', '', '<ReportPlus_OperationProperties sqlText="SELECT distinct clientName, Type FROM cf_SurveyClient with (nolock) where CommservUniqueId = @uniqID and Deleted = 0 and InstallStatus = 0 union (select ClientGroupName as clientName, -1 as Type from cf_surveyClientGroup with (nolock) where CommservUniqueId =@uniqID)">


	<parameters name="uniqID" dataType="0" />

	</ReportPlus_OperationProperties>')

END

ELSE

BEGIN

	UPDATE APP_DataStatements SET operation = '<ReportPlus_OperationProperties sqlText="SELECT distinct clientName, Type FROM cf_SurveyClient with (nolock) where CommservUniqueId = @uniqID and Deleted = 0 and InstallStatus = 0 union (select ClientGroupName as clientName, -1 as Type from cf_surveyClientGroup with (nolock) where CommservUniqueId =@uniqID)"><parameters name="uniqID" dataType="0" /></ReportPlus_OperationProperties>'

	WHERE NAME = 'GATHERLOG_COMMCELL_CLIENTS_LIST'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_GET_ENTITIES')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_GET_ENTITIES', '', '<ReportPlus_OperationProperties sqlText="SELECT * FROM ms_GetEntityIdName(@entityType, @reportType, @entityId)"><parameters name="entityType" dataType="0" /><parameters name="reportType" dataType="0" /><parameters name="entityId" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_SCORECARD_DETAILS_RESTORE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_SCORECARD_DETAILS_RESTORE', '', '<ReportPlus_OperationProperties sqlText="SELECT DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS ''DC'', TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success&lt;MSSuccessJobs&gt;'', Fail AS ''Fail&lt;MSFailedJobs&gt;'', Others AS ''Others&lt;MSOtherJobs&gt;'', Rate AS ''%Rate&lt;MSJobsRate&gt;'' FROM DBO.[ms_DCRestoreHealthInfo](@dcId, @startDate, NULL)"><parameters name="dcId" dataType="5" /><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_SCORECARD_DETAILS_BACKUP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_SCORECARD_DETAILS_BACKUP', '', '<ReportPlus_OperationProperties sqlText="SELECT DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS ''DC'', TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success&lt;MSSuccessJobs&gt;'', Fail AS ''Fail&lt;MSFailedJobs&gt;'', Others AS ''Others&lt;MSOtherJobs&gt;'', Rate AS ''%Rate&lt;MSJobsRate&gt;'' FROM DBO.[ms_DCHealthInfo](@dcId, @startDate, NULL)"><parameters name="dcId" dataType="5" /><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_SCORECARD_SUMMARY_RESTORE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_SCORECARD_SUMMARY_RESTORE', '', '<ReportPlus_OperationProperties sqlText="SELECT TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success'', Fail AS ''Fail'', Others AS ''Others'', Rate AS ''%Rate'' FROM DBO.[ms_DCRestoreHealthInfo](-1, @startDate, NULL)"><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_SCORECARD_SUMMARY_BACKUP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_SCORECARD_SUMMARY_BACKUP', '', '<ReportPlus_OperationProperties sqlText="SELECT TotClients AS ''Clients'', TotBackupVolGB AS [Vol GB], Jobs AS ''Jobs'', Success AS ''Success'', Fail AS ''Fail'', Others AS ''Others'', Rate AS ''%Rate'' FROM DBO.[ms_DCHealthInfo](-1, @startDate, NULL)"><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_SCORECARD_DAILY_DETAILS_RESTORE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_SCORECARD_DAILY_DETAILS_RESTORE', '', '<ReportPlus_OperationProperties sqlText="SELECT Date AS ''Date&lt;DONOTSHOW&gt;'', Day, TotalJobs AS ''Jobs'', SucJobs AS ''Success&lt;MSSuccessJobsDay&gt;'', FailedJobs As ''Fail&lt;MSFailedJobsDay&gt;'', Others AS ''Others&lt;MSOtherJobsDay&gt;'', SLAPerc AS ''%Rate&lt;MSJobsRate&gt;'' FROM DBO.[ms_RestoreSummaryByMonth](0, 0, @startDate, NULL)"><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_SCORECARD_DAILY_DETAILS_BACKUP')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_SCORECARD_DAILY_DETAILS_BACKUP', '', '<ReportPlus_OperationProperties sqlText="SELECT Date AS ''Date&lt;DONOTSHOW&gt;'', Day, TotalJobs AS ''Jobs'', SucJobs AS ''Success&lt;MSSuccessJobsDay&gt;'', FailedJobs As ''Fail&lt;MSFailedJobsDay&gt;'', Others AS ''Others&lt;MSOtherJobsDay&gt;'', SLAPerc AS ''%Rate&lt;MSJobsRate&gt;'' FROM DBO.[ms_BackupSummaryByMonth](0, 0, 0, @startDate, NULL)"><parameters name="startDate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_BACKUPSERVER_SEARCH1')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_BACKUPSERVER_SEARCH1', '', '<ReportPlus_OperationProperties sqlText="SELECT ServerId  AS [ServerId&lt;DONOTSHOW&gt;],Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;] ,CustomerName  AS [Property Dimension] ,DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;],DataCenter AS [Data Center] ,TotalJobs AS [Job Count],SucJobs AS [Successful Backups] , FailedJobs AS [Failed Backups], Others, SLAPerc AS [%SLA]  FROM [ms_FindBackupInfo](@xmlString)"><parameters name="xmlString" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_BACKUPSERVER_SEARCH2')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_BACKUPSERVER_SEARCH2', '', '<ReportPlus_OperationProperties sqlText="SELECT ServerId  AS [ServerId&lt;DONOTSHOW&gt;],Server AS [Server&lt;MSSearchServerJobs&gt;], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;] ,CustomerName  AS [Property Dimension] ,DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;],DataCenter AS [Data Center] ,TotalJobs AS [Job Count],SucJobs AS [Successful Backups] , FailedJobs AS [Failed Backups], Others, SLAPerc AS [%SLA]  FROM [ms_FindBackupInfo](@xmlString)"><parameters name="xmlString" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_MULTIPLE_SLA_DAYS_HAS_DATA')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_MULTIPLE_SLA_DAYS_HAS_DATA', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 Days FROM cf_SurveySLASummary WHERE Days = 1"></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_GETUPGRADECOMMCELLMESSAGE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@gldbDataSetId, 'GATHERLOG_GETUPGRADECOMMCELLMESSAGE', '', '<ReportPlus_OperationProperties sqlText="select PhaseName, ccid.PhaseID, ccid.RegCode, ExpiryDate, CloudRequestID from CommcellIDUpgradePhaseMap ccid join UpgradePhases msg on ccid.PhaseID= msg.PhaseID Where CommCellID = @CommCellID and Flags =2 and CSTFlags = 2">  <parameters name="CommCellID" dataType="0" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="select PhaseName, ccid.PhaseID, ccid.RegCode, ExpiryDate, CloudRequestID from CommcellIDUpgradePhaseMap ccid join UpgradePhases msg on ccid.PhaseID= msg.PhaseID Where CommCellID = @CommCellID and Flags =2 and CSTFlags = 2">  <parameters name="CommCellID" dataType="0" /></ReportPlus_OperationProperties>' WHERE name = 'GATHERLOG_GETUPGRADECOMMCELLMESSAGE'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_SETUPGRADECOMMCELLMESSAGE')

BEGIN
        INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@gldbDataSetId, 'GATHERLOG_SETUPGRADECOMMCELLMESSAGE', '', '<ReportPlus_OperationProperties sqlText="IF exists (SELECT 1 FROM CommcellIDUpgradePhaseMap Where CommCellID = @CommCellID) BEGIN UPDATE CommcellIDUpgradePhaseMap set PhaseID = @PhaseID , logdate = getdate() Where CommCellID = @CommCellID END ELSE BEGIN insert into [CommcellIDUpgradePhaseMap](commcellid,PhaseID,Flags,CSTFlags) values(@CommCellID,@PhaseID,2,2) END;select PhaseName, ccid.PhaseID from CommcellIDUpgradePhaseMap ccid join UpgradePhases msg on ccid.PhaseID= msg.PhaseID Where CommCellID = @CommCellID"><parameters name="CommCellID" dataType="0" /><parameters name="PhaseID" dataType="5" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="IF exists (SELECT 1 FROM CommcellIDUpgradePhaseMap Where CommCellID = @CommCellID) BEGIN UPDATE CommcellIDUpgradePhaseMap set PhaseID = @PhaseID , logdate = getdate() Where CommCellID = @CommCellID END ELSE BEGIN insert into [CommcellIDUpgradePhaseMap](commcellid,PhaseID,Flags,CSTFlags) values(@CommCellID,@PhaseID,2,2) END;select PhaseName, ccid.PhaseID from CommcellIDUpgradePhaseMap ccid join UpgradePhases msg on ccid.PhaseID= msg.PhaseID Where CommCellID = @CommCellID"><parameters name="CommCellID" dataType="0" /><parameters name="PhaseID" dataType="5" /></ReportPlus_OperationProperties>' WHERE name = 'GATHERLOG_SETUPGRADECOMMCELLMESSAGE'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADEJOBS_TOP_RESULTID_1')

BEGIN
        INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADEJOBS_TOP_RESULTID_1', '', '<ReportPlus_OperationProperties sqlText="IF (SELECT COUNT(*) FROM cf_SurveyUpgradeCheck where CommServUniqueId = @commUniId AND LogDateUTC BETWEEN @upgradedate and DATEADD(day,22,@upgradedate)) = 0 SELECT TOP 1 SurveyResultId from cf_SurveyUpgradeCheck where CommServUniqueId = @commUniId and LogDateUTC &gt; DATEADD(day,22,@upgradedate) ELSE SELECT TOP 1 SurveyResultId from cf_SurveyUpgradeCheck where CommServUniqueId = @commUniId and LogDateUTC BETWEEN @upgradedate and DATEADD(day,22,@upgradedate) order by LogDateUTC desc">  <parameters name="commUniId" dataType="5" />  <parameters name="upgradedate" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADEJOBS_TOP_RESULTID_2')

BEGIN
        INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADEJOBS_TOP_RESULTID_2', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 SurveyResultId FROM cf_SurveyUpgradeCheck WHERE CommServUniqueId = @commUniId order by SurveyResultId DESC">  <parameters name="commUniId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADEPREJOBS')

BEGIN
        INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADEPREJOBS', '', '<ReportPlus_OperationProperties sqlText="select DISTINCT(AppTypeName),SUM(SuccessfulJobs) Completed, SUM([CWEJobs]) CWE, SUM(AvgJobThroughput) AvgJobThroughput,SUM(AvgJobRunTime) AvgJobRunTime,SUM(AvgJobAttempts) AvgJobAttempts,SUM(FailedJobs) Failed, failureReason ,SUM(KilledJobs) Killed from cf_SurveyUpgradeCheck where CommServUniqueId = @commUniId and UpgradeType = 1 and Days = @days and SurveyResultId = (SELECT TOP 1 SurveyResultId from cf_SurveyUpgradeCheck where CommServUniqueId = @commUniId and LogDateUTC &gt; @upgradedate ) group by appTypeName,failureReason">  <parameters name="commUniId" dataType="5" />  <parameters name="days" dataType="0" />  <parameters name="upgradedate" dataType="2" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYPREPOSTUPGRADEPOSTJOBS')

BEGIN
        INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYPREPOSTUPGRADEPOSTJOBS', '', '<ReportPlus_OperationProperties sqlText="select DISTINCT(AppTypeName),CONVERT(VARCHAR(11),LogDateUTC,6) LogDateUTC,SUM(SuccessfulJobs) Completed, SUM([CWEJobs]) CWE, SUM(AvgJobThroughput) AvgJobThroughput,SUM(AvgJobRunTime) AvgJobRunTime,SUM(AvgJobAttempts) AvgJobAttempts,SUM(FailedJobs) Failed, failureReason ,SUM(KilledJobs) Killed from cf_SurveyUpgradeCheck where CommServUniqueId = @commUniId and UpgradeType = @UpgradeType and Days = @days and SurveyResultId = @SurveyResultId group by appTypeName,failureReason,LogDateUTC">  <parameters name="commUniId" dataType="5" />  <parameters name="upgradeType" dataType="0" />  <parameters name="days" dataType="0" />  <parameters name="surveyResultId" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_BACKUP_JOBS_SERVERS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_BACKUP_JOBS_SERVERS', '', '<ReportPlus_OperationProperties sqlText="SELECT JobId AS [Job], ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], BackupContent AS [Target], JobStartDateTime AS [Start Time&lt;dateTimeRenderer&gt;], [JobEndDateTime] AS [Finish Time&lt;dateTimeRenderer&gt;], BackupLevel AS [Level], TotBackupVolGB AS [Vol GB], FilesSkipped AS [Files Skipped], Retention AS [Days Retained], JobStatus AS [Job Status] FROM DBO.[ms_FindBackupJobInfo](@xmlString)"><parameters name="xmlString" dataType="0" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'MSDB_RESTORE_JOBS_SERVERS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@msDbDataSetId, 'MSDB_RESTORE_JOBS_SERVERS', '', '<ReportPlus_OperationProperties sqlText="SELECT JobId AS [Job], ServerId AS [ServerId&lt;DONOTSHOW&gt;], Server AS [Server], CustomerId AS [CustomerId&lt;DONOTSHOW&gt;], CustomerName AS [Property Dimension], DataCenterId AS [DataCenterId&lt;DONOTSHOW&gt;], DataCenter AS [Data Center], JobStartDateTime AS [Start Time&lt;dateTimeRenderer&gt;], [JobEndDateTime] AS [Finish Time&lt;dateTimeRenderer&gt;], FilesSkipped AS [Files Skipped], restoreJobDurationMinutes AS [Job Duration(Minutes)], JobStatus AS [Job Status] FROM DBO.[ms_FindRestoreJobInfo](@xmlString)"><parameters name="xmlString" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_DUPLICATE_COMMCELL_COUNT')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_DUPLICATE_COMMCELL_COUNT', '', '<ReportPlus_OperationProperties sqlText="select count(commcellid) as commcellcount from cf_CommcellIdNameMap with(nolock) where (flags &amp; 1) = 0 and commcellid = @commcellId"><parameters name="commcellId" dataType="5" /></ReportPlus_OperationProperties>')


END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_GETAVGDEDUPRATIO')

BEGIN
       INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId,'METRICS_GETAVGDEDUPRATIO','','<ReportPlus_OperationProperties sqlText="SELECT (CASE WHEN TotalAppSizeGB &gt; 0 AND TotalSavingGB &gt; 0 THEN CAST(TotalSavingGB/(0.01*TotalAppSizeGB) AS DECIMAL(6, 2)) ELSE 0 END) as CCAvg, TotalMediaSizeGB, TotalAppSizeGB FROM (SELECT SUM(TotalAppSizeGB) AS TotalAppSizeGB, (SUM(TotalAppSizeGB) - SUM(TotalMediaSizeGB)) AS TotalSavingGB, SUM(TotalMediaSizeGB) AS TotalMediaSizeGB FROM dbo.cf_SurveyResultFuncV1(146, @commUniId, 1, NULL, NULL, &lt;loginUserId&gt;, @ccGroupId) R INNER JOIN cf_CommcellSummary S ON S.SurveyResultId = R.SurverResultId WHERE NOT (TotalAppSizeGB &lt; TotalMediaSizeGB)) T"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

       UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="SELECT (CASE WHEN TotalAppSizeGB &gt; 0 AND TotalSavingGB &gt; 0 THEN CAST(TotalSavingGB/(0.01*TotalAppSizeGB) AS DECIMAL(6, 2)) ELSE 0 END) as CCAvg, TotalMediaSizeGB, TotalAppSizeGB FROM (SELECT SUM(TotalAppSizeGB) AS TotalAppSizeGB, (SUM(TotalAppSizeGB) - SUM(TotalMediaSizeGB)) AS TotalSavingGB, SUM(TotalMediaSizeGB) AS TotalMediaSizeGB FROM dbo.cf_SurveyResultFuncV1(146, @commUniId, 1, NULL, NULL, &lt;loginUserId&gt;, @ccGroupId) R INNER JOIN cf_CommcellSummary S ON S.SurveyResultId = R.SurverResultId WHERE NOT (TotalAppSizeGB &lt; TotalMediaSizeGB)) T"><parameters name="commUniId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>' WHERE name='METRICS_GETAVGDEDUPRATIO'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_QUERY174_RESULTS_EXIST')

BEGIN
      INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_QUERY174_RESULTS_EXIST', '', '<ReportPlus_OperationProperties sqlText="SELECT TOP 1 CommservSurveyResults_ID FROM cf_CommservSurveyResults WITH(NOLOCK) WHERE QueryId = 174 AND ShredStatus = 2"></ReportPlus_OperationProperties>')            


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_BINARY_LIST')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'GATHERLOG_BINARY_LIST', '', '<ReportPlus_OperationProperties sqlText="select sbinaryname as bname from updatecenter.produpdatecenter.dbo.cvbinaryinfo where nplatformid=1 and sbinaryname like ''%.exe%'' order by sbinaryname"><parameters name="uniqID" dataType="0" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="select sbinaryname as bname from updatecenter.produpdatecenter.dbo.cvbinaryinfo where nplatformid=1 and sbinaryname like ''%.exe%'' order by sbinaryname"><parameters name="uniqID" dataType="0" /></ReportPlus_OperationProperties>' where name='GATHERLOG_BINARY_LIST'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_COMMCELL_ALERTS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_COMMCELL_ALERTS', '', '<ReportPlus_OperationProperties sqlText="EXEC RptGetCommCellAlerts &lt;loginUserId&gt;, @ccGroupId, @aggregate, @commUniId, @topNAlerts, @lastNDays, null, null"><parameters name="ccGroupId" dataType="0" /><parameters name="aggregate" dataType="0" /><parameters name="commUniId" dataType="0" /><parameters name="topNAlerts" dataType="0" /><parameters name="lastNDays" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_GETDEFAULTINPUTFOREXECSUMMARY')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_GETDEFAULTINPUTFOREXECSUMMARY', '', '<ReportPlus_OperationProperties sqlText="SELECT [ExecSummary_DefaultHeadName] AS DefaultHeadName, [ExecSummary_DefaultDesignation] AS DefaultDesignation FROM (SELECT Name, Value FROM cf_SurveyConfig WITH(NOLOCK) WHERE Name IN (&#39;ExecSummary_DefaultHeadName&#39;, &#39;ExecSummary_DefaultDesignation&#39;)) AS S PIVOT ( MAX(Value) FOR Name IN ([ExecSummary_DefaultHeadName], [ExecSummary_DefaultDesignation])) AS P"></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_LAST_RELEASE_SERVICEPACK')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'GATHERLOG_LAST_RELEASE_SERVICEPACK', '', '<ReportPlus_OperationProperties sqlText="SELECT top 1 sTargetName from updatecenter.produpdatecenter.dbo.cvtargets where nreleaseid in (select nreleaseid from updatecenter.produpdatecenter.dbo.cvrelease) and dateExternal &lt; getdate() order by nbuildid desc"> </ReportPlus_OperationProperties>')


END

ELSE

BEGIN

       UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="SELECT top 1 sTargetName from updatecenter.produpdatecenter.dbo.cvtargets where nreleaseid in (select nreleaseid from updatecenter.produpdatecenter.dbo.cvrelease) and dateExternal &lt; getdate() order by nbuildid desc"> </ReportPlus_OperationProperties>', dataSetId = @dataSetId WHERE name='GATHERLOG_LAST_RELEASE_SERVICEPACK'

END	

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GLDB_GET_REQUESTID_BY_REPORTID')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@gldbDataSetId, 'GLDB_GET_REQUESTID_BY_REPORTID', '', '<ReportPlus_OperationProperties sqlText="SELECT RequestId FROM CloudRequestData WHERE DataName=''SurveyReportId'' and DataValue= @reportId"><parameters name="reportId" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GLDB_GET_REQUESTTYPEID_BY_REQUEST_TYPE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@gldbDataSetId, 'GLDB_GET_REQUESTTYPEID_BY_REQUEST_TYPE', '', '<ReportPlus_OperationProperties sqlText="SELECT requestTypeId FROM RequestType WHERE RequestType = @requestType"><parameters name="requestType" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GATHERLOG_STAGING_SERVICEPACKS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'GATHERLOG_STAGING_SERVICEPACKS', '', '<ReportPlus_OperationProperties sqlText="select DATEDIFF(month,cvt.dateExternal,getdate()) as releasedBeforeMonths,


cvt.nReleaseID,cvt.sTargetName,cvt.dateExternal as releasedDate from updatecenter.produpdatecenter.dbo.cvtargets cvt 

left join updatecenter.produpdatecenter.dbo.BuildInfo bi on cvt.nbuildid=bi.nbuildid

where cvt.sBuildType like ''HotFix'' and cvt.nBuildid &lt;&gt; 0  

and ((cvt.dateExternal &lt; getdate()   and 

DATEDIFF(month,cvt.dateExternal,getdate()) &lt;=12) or  

(bi.nbuildid = (select nBuildID from updatecenter.produpdatecenter.dbo.BuildProperties where nbuildid=bi.nbuildid

	and sPropertyName = ''LTSBuild'' and sPropertyValue = ''true'' 

)))

order by cvt.nbuildid asc"> </ReportPlus_OperationProperties>')

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'COMMSRV_GET_CLOUDAUTH_REF_EMAIL')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@ccDataSetId, 'COMMSRV_GET_CLOUDAUTH_REF_EMAIL', '', '<ReportPlus_OperationProperties sqlText="select isnull(cvreferral, '''') as referralemail from CloudAuthorization where id=(select cast(attrVal as int) from UMUsersProp where componentNameId = &lt;loginUserId&gt; and attrName=''Cloud Auth Code'')"></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'DOCUMENT_REPORT_GET_DETAILS')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@ccDataSetId, 'DOCUMENT_REPORT_GET_DETAILS', '', '<ReportPlus_OperationProperties sqlText="select name, guid, reportType, definition from APP_DocumentReport WHERE guid = @guid"><parameters name="guid" dataType="0" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_ADD_NOTE')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_ADD_NOTE', '', '<ReportPlus_OperationProperties sqlText="EXEC RptSetNote @note, @commcellID, @queryID, @paramID, &lt;loginUserId&gt;"><parameters name="note" dataType="0" /><parameters name="commcellID" dataType="5" /><parameters name="queryID" dataType="5" /><parameters name="paramID" dataType="5" /></ReportPlus_OperationProperties>')


END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'GET_TENANTS_FOR_USER')

BEGIN
	INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'GET_TENANTS_FOR_USER', '', '<ReportPlus_OperationProperties sqlText="IF (select [dbo].[isMSPViewEnabled]()) = 1 SELECT DISTINCT ST.TenantName FROM cf_SurveyTenants ST WITH (NOLOCK) INNER JOIN ( SELECT CommServUniqueId, CommServName FROM dbo.cf_SurveyResultFuncV1(251, @CSUniqueId, 1, NULL, NULL, &lt;loginUserId&gt;, @ccGroupId)) S ON ST.CommServUniqueId = S.CommServUniqueId"><parameters name="CSUniqueId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>')


END

ELSE

BEGIN

	UPDATE  APP_DATASTATEMENTS SET operation='<ReportPlus_OperationProperties sqlText="IF (select [dbo].[isMSPViewEnabled]()) = 1 SELECT DISTINCT ST.TenantName FROM cf_SurveyTenants ST WITH (NOLOCK) INNER JOIN ( SELECT CommServUniqueId, CommServName FROM dbo.cf_SurveyResultFuncV1(251, @CSUniqueId, 1, NULL, NULL, &lt;loginUserId&gt;, @ccGroupId)) S ON ST.CommServUniqueId = S.CommServUniqueId"><parameters name="CSUniqueId" dataType="5" /><parameters name="ccGroupId" dataType="5" /></ReportPlus_OperationProperties>', dataSetId = @dataSetId WHERE name='GET_TENANTS_FOR_USER'

END

IF NOT EXISTS (SELECT * FROM APP_DATASTATEMENTS WHERE NAME = 'METRICS_CF_SURVEYCONFIG_CUSTOMDOCUMENT_GUID')

BEGIN
    INSERT INTO APP_DATASTATEMENTS(dataSetId, name, description, operation) values(@dataSetId, 'METRICS_CF_SURVEYCONFIG_CUSTOMDOCUMENT_GUID', '', '<ReportPlus_OperationProperties sqlText="SELECT Name FROM cf_surveyConfig WITH (NOLOCK) WHERE Value = @val"><parameters name="val" dataType="0" /></ReportPlus_OperationProperties>')


END  
