Microsoft.Windows.Client.Win10.Dataset.Memory (DataWarehouseDataSet)

Element properties:

AccessibilityPublic

Source Code:

<DataWarehouseDataSet ID="Microsoft.Windows.Client.Win10.Dataset.Memory" Accessibility="Public">
<Dependencies>
<DataWarehouseScript>SCDW!Microsoft.SystemCenter.DataWarehouse.Script.DatasetDebuggingSupport</DataWarehouseScript>
<DataWarehouseScript>SCDW!Microsoft.SystemCenter.DataWarehouse.Script.StandardDatasetSupport</DataWarehouseScript>
</Dependencies>
<Configuration>
<IncludeSchemaTypes>
<SchemaType>SCDW!Microsoft.SystemCenter.DataWarehouse.StandardDatasetSchema</SchemaType>
</IncludeSchemaTypes>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Aggregations" type="AggregationsType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="RawInsertTableCount" type="xsd:positiveInteger"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="DefaultAggregationIntervalCount" type="xsd:positiveInteger"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BlockingMaintenanceDailyStartTime" type="TimeOfDayType"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BlockingMaintenanceDurationMinutes" type="xsd:positiveInteger"/>
</Configuration>
<Install> SET NOCOUNT ON
GO

DECLARE
@DatasetId uniqueidentifier

IF EXISTS (SELECT * FROM StandardDatasetAggregationStorage WHERE DatasetId IN (SELECT DatasetId FROM StandardDataset WHERE SchemaName = 'Win10') AND BaseTableName = 'Win10MemoryHealthRaw')
BEGIN
SET @DatasetId = (SELECT DatasetId FROM StandardDatasetAggregationStorage WHERE DatasetId IN (SELECT DatasetId FROM StandardDataset WHERE SchemaName = 'Win10') AND BaseTableName = 'Win10MemoryHealthRaw')
EXEC StandardDatasetDelete @DatasetId
END
SET NOCOUNT ON
GO

INSERT StandardDataset (
DatasetId
,SchemaName
,DefaultAggregationIntervalCount
,RawInsertTableCount
,BlockingMaintenanceDailyStartTime
,BlockingMaintenanceDurationMinutes
)
VALUES
(
'$Config/DatasetId$'
,'Win10'
,$Config/DefaultAggregationIntervalCount$
,$Config/RawInsertTableCount$
,'$Config/BlockingMaintenanceDailyStartTime$'
,$Config/BlockingMaintenanceDurationMinutes$
)

SET NOCOUNT ON

DECLARE
@ErrorInd bit
,@ErrorMessageText nvarchar(4000)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)

SET @ErrorInd = 0

DECLARE
@ExecResult int
,@XmlDocHandle int
,@XmlDocText nvarchar(max)

BEGIN TRY
SET @XmlDocText = '&lt;Aggregations&gt;$Config/Aggregations$&lt;/Aggregations&gt;'

EXEC @ExecResult = sp_xml_preparedocument @XmlDocHandle OUTPUT, @XmlDocText
IF @ExecResult &lt;&gt; 0 RAISERROR(777971000, 16, 1, 'MemoryAggregation', @ExecResult)

INSERT StandardDatasetAggregation
(
DatasetId
,AggregationTypeId
,AggregationIntervalDurationMinutes
,AggregationStartDelayMinutes
,BuildAggregationStoredProcedureName
,DeleteAggregationStoredProcedureName
,GroomStoredProcedureName
,IndexOptimizationIntervalMinutes
,MaxDataAgeDays
,GroomingIntervalMinutes
,MaxRowsToGroom
,LastGroomingDateTime
,DataFileGroupName
,IndexFileGroupName
)
SELECT
'$Config/DatasetId$'
,CASE AggregationType
WHEN 'Raw' THEN 0
WHEN 'Daily' THEN 30
END
,CASE AggregationType
WHEN 'Raw' THEN 0
WHEN 'Daily' THEN 24*60
END
,AggregationStartDelayMinutes
,CASE AggregationType
WHEN 'Raw' THEN NULL
ELSE 'Win10MemoryAggregate'
END
,CASE AggregationType
WHEN 'Raw' THEN NULL
ELSE 'Win10MemoryAggregationDelete'
END
,'Win10MemoryGroom'
,IndexOptimizationIntervalMinutes
,MaxDataAgeDays
,GroomingIntervalMinutes
,MaxRowsToGroom
,GETUTCDATE()
,DataFileGroupName
,IndexFileGroupName
FROM OPENXML(@XmlDocHandle, 'Aggregations/*', 2) WITH (
AggregationType varchar(50) '@mp:localname'
,MaxTableRowCount int
,MaxTableSizeKb int
,AggregationStartDelayMinutes int
,MaxDataAgeDays int
,GroomingIntervalMinutes int
,MaxRowsToGroom int
,IndexOptimizationIntervalMinutes int
,DataFileGroupName nvarchar(256)
,IndexFileGroupName nvarchar(256)
,AggregationIntervalDurationMinutes int
)
END TRY
BEGIN CATCH
SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

IF (@XmlDocHandle IS NOT NULL)
EXEC sp_xml_removedocument @XmlDocHandle

IF (@ErrorInd = 1)
BEGIN
DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 1
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
GO


SET NOCOUNT ON

DECLARE
@ErrorInd bit
,@ErrorMessageText nvarchar(4000)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)

SET @ErrorInd = 0

DECLARE
@ExecResult int
,@XmlDocHandle int
,@XmlDocText nvarchar(max)
,@MaxTableRowCount int
,@MaxTableSizeKb int

SELECT
@MaxTableSizeKb = NULLIF('$Config/Storage/MaxTableSizeKb$', '')
,@MaxTableRowCount = NULLIF('$Config/Storage/MaxTableRowCount$', '')

BEGIN TRY

-- Inserting info about raw aggregations
INSERT StandardDatasetAggregationStorage
(
DatasetId
,AggregationTypeId
,BaseTableName
,DependentTableInd
,TableTemplate
,CoverViewSelectClause
,MaxTableRowCount
,MaxTableSizeKb
)
VALUES
(
'$Config/DatasetId$'
,0
,'Win10MemoryHealthRaw'
,0
,'
CREATE TABLE [Win10].[Win10MemoryHealthRaw_$Guid$]
(
Win10MemoryHealthRawRowId int NOT NULL IDENTITY(1, 1)
,[DateTime] datetime NOT NULL
,EventDataRowId int NOT NULL
,ComputerDataRowId int NOT NULL
,PrincipalName nvarchar(256) NOT NULL
,RAM bigint NOT NULL
,App1 nvarchar(256) NOT NULL
,App2 nvarchar(256) NOT NULL
,App3 nvarchar(256) NOT NULL
,App1_Mem bigint NOT NULL
,App2_Mem bigint NOT NULL
,App3_Mem bigint NOT NULL
,CONSTRAINT [PK_Win10MemoryHealthRaw_$Guid$] PRIMARY KEY CLUSTERED (Win10MemoryHealthRawRowId) ON $DataFileGroupName$
) ON $DataFileGroupName$
'
,'
SELECT
[DateTime]
,Win10MemoryHealthRawRowId
,EventDataRowId
,ComputerDataRowId
,PrincipalName
,RAM
,App1
,App2
,App3
,App1_Mem
,App2_Mem
,App3_Mem
'
,@MaxTableRowCount
,@MaxTableSizeKb
)

-- Inserting info about raw aggregations
INSERT StandardDatasetAggregationStorage
(
DatasetId
,AggregationTypeId
,BaseTableName
,TableTag
,DependentTableInd
,TableTemplate
,CoverViewSelectClause
,MaxTableRowCount
,MaxTableSizeKb
)
VALUES
(
'$Config/DatasetId$'
,0
,'Win10MemoryFailureRaw'
,'Memory Failure'
,1
,'
CREATE TABLE [Win10].[Win10MemoryFailureRaw_$Guid$]
(
Win10MemoryFailureRawRowId int NOT NULL IDENTITY(1, 1)
,[DateTime] datetime NOT NULL
,EventDataRowId int NOT NULL
,ComputerDataRowId int NOT NULL
,PrincipalName nvarchar(256) NOT NULL
,RAM bigint NOT NULL
,CONSTRAINT [PK_Win10MemoryFailureRaw_$Guid$] PRIMARY KEY CLUSTERED (Win10MemoryFailureRawRowId) ON $DataFileGroupName$
) ON $DataFileGroupName$
'
,'
SELECT
[DateTime]
,Win10MemoryFailureRawRowId
,EventDataRowId
,ComputerDataRowId
,PrincipalName
,RAM
'
,@MaxTableRowCount
,@MaxTableSizeKb
)

-- Now getting to Daily Aggregations
-- RAM Chart Aggregation
INSERT StandardDatasetAggregationStorage
(
DatasetId
,AggregationTypeId
,BaseTableName
,DependentTableInd
,TableTemplate
,CoverViewSelectClause
,MaxTableRowCount
,MaxTableSizeKb
)
VALUES
(
'$Config/DatasetId$'
,30
,'Win10MemoryHealthAggregationRAM'
,0
,'
CREATE TABLE [Win10].[Win10MemoryHealthAggregationRAM_$Guid$]
(
Win10MemoryHealthAggregationRAMRowId int NOT NULL IDENTITY(1, 1)
,[DateTime] datetime NOT NULL
,NumEvents int NOT NULL
,NumComputers int NOT NULL
,RAM bigint NOT NULL
,CONSTRAINT [PK_Win10MemoryHealthAggregationRAM_$Guid$] PRIMARY KEY CLUSTERED (Win10MemoryHealthAggregationRAMRowId) ON $DataFileGroupName$
) ON $DataFileGroupName$
'
,'
SELECT
[DateTime]
,Win10MemoryHealthAggregationRAMRowId
,NumComputers
,NumEvents
,RAM
'
,@MaxTableRowCount
,@MaxTableSizeKb
)

-- Computer Chart Aggregation
INSERT StandardDatasetAggregationStorage
(
DatasetId
,AggregationTypeId
,BaseTableName
,TableTag
,DependentTableInd
,TableTemplate
,CoverViewSelectClause
,MaxTableRowCount
,MaxTableSizeKb
)
VALUES
(
'$Config/DatasetId$'
,30
,'Win10MemoryHealthAggregationComputer'
,'Memory Computer'
,1
,'
CREATE TABLE [Win10].[Win10MemoryHealthAggregationComputer_$Guid$]
(
Win10MemoryHealthAggregationComputerRowId int NOT NULL IDENTITY(1, 1)
,[DateTime] datetime NOT NULL
,ComputerDataRowId int NOT NULL
,NumEvents int NOT NULL
,NumComputers int NOT NULL
,CONSTRAINT [PK_Win10MemoryHealthAggregationComputer_$Guid$] PRIMARY KEY CLUSTERED (Win10MemoryHealthAggregationComputerRowId) ON $DataFileGroupName$
) ON $DataFileGroupName$
'
,'
SELECT
[DateTime]
,Win10MemoryHealthAggregationComputerRowId
,ComputerDataRowId
,NumEvents
,NumComputers
'
,@MaxTableRowCount
,@MaxTableSizeKb
)


-- App chart/drilldown aggregation
INSERT StandardDatasetAggregationStorage
(
DatasetId
,AggregationTypeId
,BaseTableName
,TableTag
,DependentTableInd
,TableTemplate
,CoverViewSelectClause
,MaxTableRowCount
,MaxTableSizeKb
)
VALUES
(
'$Config/DatasetId$'
,30
,'Win10MemoryHealthAggregationApp'
,'Memory App'
,1
,'
CREATE TABLE [Win10].[Win10MemoryHealthAggregationApp_$Guid$]
(
Win10MemoryHealthAggregationAppRowId int NOT NULL IDENTITY(1, 1)
,[DateTime] datetime NOT NULL
,AppName nvarchar(256) NOT NULL
,AvgApp_Mem bigint NOT NULL
,NumInstances int NOT NULL
,CONSTRAINT [PK_Win10MemoryHealthAggregationApp_$Guid$] PRIMARY KEY CLUSTERED (Win10MemoryHealthAggregationAppRowId) ON $DataFileGroupName$
) ON $DataFileGroupName$
'
,'
SELECT
[DateTime]
,Win10MemoryHealthAggregationAppRowId
,AppName
,AvgApp_Mem
,NumInstances
'
,@MaxTableRowCount
,@MaxTableSizeKb
)

END TRY
BEGIN CATCH
SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

IF (@XmlDocHandle IS NOT NULL)
EXEC sp_xml_removedocument @XmlDocHandle

IF (@ErrorInd = 1)
BEGIN
DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 1
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE [name] = 'Win10')
BEGIN
EXECUTE('CREATE SCHEMA Win10')
END
GO

-- change schema ownership to allow index rebuild and reorganize
ALTER AUTHORIZATION ON SCHEMA::Win10 TO OpsMgrWriter
GO

-- change schema alter to allow domain table index rebuild
GRANT ALTER ON SCHEMA::dbo TO OpsMgrWriter
GO

-- grant create table permissions
GRANT CREATE TABLE TO OpsMgrWriter
GO

SET NOCOUNT ON

DECLARE
@ErrorInd bit
,@ErrorMessageText nvarchar(4000)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)

SET @ErrorInd = 0

DECLARE
@ExecResult int
,@XmlDocHandle int
,@XmlDocText nvarchar(max)

BEGIN TRY
SET @XmlDocText = '&lt;Aggregations&gt;$Config/Aggregations$&lt;/Aggregations&gt;'

EXEC @ExecResult = sp_xml_preparedocument @XmlDocHandle OUTPUT, @XmlDocText
IF @ExecResult &lt;&gt; 0 RAISERROR(777971000, 16, 1, 'MemoryAggregation', @ExecResult)

DECLARE
@AggregationType varchar(50)
,@Statement nvarchar(max)

SET @AggregationType = ''

WHILE EXISTS (SELECT *
FROM OPENXML(@XmlDocHandle, 'Aggregations/*', 2) WITH (
AggregationType varchar(50) '@mp:localname')
WHERE AggregationType &gt; @AggregationType
)
BEGIN
SELECT TOP 1 @AggregationType = AggregationType
FROM OPENXML(@XmlDocHandle, 'Aggregations/*', 2) WITH (
AggregationType varchar(50) '@mp:localname')
WHERE AggregationType &gt; @AggregationType
ORDER BY AggregationType

SET @Statement = 'EXEC StandardDatasetAllocateStorage @DatasetId = ''$Config/DatasetId$'', @AggregationTypeId='
+ CASE @AggregationType
WHEN 'Raw' THEN '0'
WHEN 'Daily' THEN '30'
END
EXECUTE (@Statement)
END
END TRY
BEGIN CATCH
SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

IF (@XmlDocHandle IS NOT NULL)
EXEC sp_xml_removedocument @XmlDocHandle

IF (@ErrorInd = 1)
BEGIN
DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 1
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
GO

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'EventData' AND TABLE_SCHEMA = 'Win10')
BEGIN
DROP TABLE Win10.EventData
END
GO

CREATE TABLE Win10.EventData
(
EventDataRowId int NOT NULL IDENTITY(1, 1)
,EventId int NOT NULL
,PublisherName nvarchar(256) NOT NULL
,CONSTRAINT PK_Win10_EventRule PRIMARY KEY CLUSTERED (EventDataRowId)
)
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'ComputerData' AND TABLE_SCHEMA = 'Win10')
BEGIN
DROP TABLE Win10.ComputerData
END
GO

CREATE TABLE Win10.ComputerData
(
ComputerDataRowId int NOT NULL IDENTITY(1, 1)
,Manufacturer nvarchar(256) NOT NULL
,Model nvarchar(256) NOT NULL
,CONSTRAINT PK_Win10_ComputerRule PRIMARY KEY CLUSTERED (ComputerDataRowId)
)

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAggregationDelete')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryAggregationDelete AS RETURN 1')
END
GO
ALTER PROCEDURE dbo.Win10MemoryAggregationDelete
@DatasetId uniqueidentifier
,@AggregationTypeId tinyint
,@TableGuid uniqueidentifier
,@AggregationDateTime datetime
,@RowsDeleted int OUTPUT
AS
BEGIN
SET NOCOUNT ON

DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(4000)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(4000)

SET @ErrorInd = 0

DECLARE
@Statement nvarchar(max)

BEGIN TRY
IF @AggregationTypeId = 30
BEGIN
SET @Statement = 'DELETE FROM Win10.vWin10MemoryHealthAggregationRAM'
+ ' WHERE ([DateTime] = CONVERT(datetime, ''' + CONVERT(varchar(50), @AggregationDateTime, 120) + ''', 120))'
EXECUTE(@Statement)

SET @RowsDeleted = @@ROWCOUNT

SET @Statement = 'DELETE FROM Win10.vWin10MemoryHealthAggregationComputer'
+ ' WHERE ([DateTime] = CONVERT(datetime, ''' + CONVERT(varchar(50), @AggregationDateTime, 120) + ''', 120))'
EXECUTE(@Statement)

SET @RowsDeleted = @@ROWCOUNT + @RowsDeleted

SET @Statement = 'DELETE FROM Win10.vWin10MemoryHealthAggregationApp'
+ ' WHERE ([DateTime] = CONVERT(datetime, ''' + CONVERT(varchar(50), @AggregationDateTime, 120) + ''', 120))'
EXECUTE(@Statement)

SET @RowsDeleted = @@ROWCOUNT + @RowsDeleted
END
END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

RETURN @RowsDeleted
END
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAggregate')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryAggregate AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryAggregate
@DatasetId uniqueidentifier
,@AggregationTypeId int
,@InsertTableGuid varchar(256)
,@IntervalStartDateTime datetime
,@IntervalEndDateTime datetime
AS
BEGIN
SET NOCOUNT ON

BEGIN TRY
DECLARE
@CompManufacturerGuid uniqueidentifier
,@CompModelGuid uniqueidentifier
,@RAMGuid uniqueidentifier

DECLARE @NoXml TABLE (ManagedEntityRowId int, ComputerDataRowId int, RAM bigint)
DECLARE @RAMTable TABLE (NumComputers int, RAM int)
DECLARE @ComputerTable TABLE (NumComputers int, ComputerDataRowId int)

SELECT @RAMGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'RAM'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

SELECT @CompManufacturerGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'Manufacturer'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

SELECT @CompModelGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'Model'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

INSERT @NoXml (
ManagedEntityRowId
,ComputerDataRowId
,RAM
) SELECT vManagedEntityProperty.ManagedEntityRowId
,Win10.ComputerData.ComputerDataRowId
,CONVERT(bigint, CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@RAMGuid")])')))
FROM vManagedEntityProperty
JOIN Win10.ComputerData ON Win10.ComputerData.Manufacturer = CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@CompManufacturerGuid")])'))
AND Win10.ComputerData.Model = CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@CompModelGuid")])'))
WHERE (CONVERT(bigint, CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@RAMGuid")])'))) &gt; 0)

UPDATE @NoXml SET RAM = RAM/1000000
UPDATE @NoXml SET RAM = (RAM - (RAM % 128)) + (RAM % 128) / 64 * 128

INSERT @RAMTable SELECT COUNT(ManagedEntityRowId), RAM
FROM @NoXml
GROUP BY RAM
INSERT @ComputerTable SELECT COUNT(ManagedEntityRowId), ComputerDataRowId
FROM @NoXml
GROUP BY ComputerDataRowId

INSERT Win10.vWin10MemoryHealthAggregationRAM (
[DateTime]
,NumEvents
,NumComputers
,RAM
) SELECT DISTINCT CONVERT(varchar(50), @IntervalStartDateTime, 120), COUNT(*), MAX(RAMTable.NumComputers), Win10.vWin10MemoryHealthRaw.RAM
FROM Win10.vWin10MemoryHealthRaw
JOIN @RAMTable As RAMTable ON (RAMTable.RAM = Win10.vWin10MemoryHealthRaw.RAM)
WHERE ([DateTime] &gt;= CONVERT(varchar(50), @IntervalStartDateTime, 120))
AND ([DateTime] &lt; CONVERT(varchar(50), @IntervalEndDateTime, 120))
GROUP BY Win10.vWin10MemoryHealthRaw.RAM

INSERT Win10.vWin10MemoryHealthAggregationComputer (
[DateTime]
,ComputerDataRowId
,NumEvents
,NumComputers
) SELECT DISTINCT CONVERT(varchar(50), @IntervalStartDateTime, 120), Win10.vWin10MemoryHealthRaw.ComputerDataRowId, COUNT(*), MAX(ComputerTable.NumComputers)
FROM Win10.vWin10MemoryHealthRaw
JOIN @ComputerTable As ComputerTable ON (ComputerTable.ComputerDataRowId = Win10.vWin10MemoryHealthRaw.ComputerDataRowId)
WHERE ([DateTime] &gt;= CONVERT(varchar(50), @IntervalStartDateTime, 120))
AND ([DateTime] &lt; CONVERT(varchar(50), @IntervalEndDateTime, 120))
GROUP BY Win10.vWin10MemoryHealthRaw.ComputerDataRowId

CREATE TABLE #MemoryAppStaging
(
AppName nvarchar(256) NOT NULL
,App_Mem bigint NOT NULL
)

INSERT #MemoryAppStaging (
AppName
,App_Mem
) SELECT App1, App1_Mem
FROM Win10.vWin10MemoryHealthRaw
WHERE ([DateTime] &gt;= CONVERT(varchar(50), @IntervalStartDateTime, 120))
AND ([DateTime] &lt; CONVERT(varchar(50), @IntervalEndDateTime, 120))

INSERT #MemoryAppStaging (
AppName
,App_Mem
) SELECT App2, App2_Mem
FROM Win10.vWin10MemoryHealthRaw
WHERE ([DateTime] &gt;= CONVERT(varchar(50), @IntervalStartDateTime, 120))
AND ([DateTime] &lt; CONVERT(varchar(50), @IntervalEndDateTime, 120))

INSERT #MemoryAppStaging (
AppName
,App_Mem
) SELECT App3, App3_Mem
FROM Win10.vWin10MemoryHealthRaw
WHERE ([DateTime] &gt;= CONVERT(varchar(50), @IntervalStartDateTime, 120))
AND ([DateTime] &lt; CONVERT(varchar(50), @IntervalEndDateTime, 120))

INSERT Win10.vWin10MemoryHealthAggregationApp (
[DateTime]
,AppName
,AvgApp_Mem
,NumInstances
) SELECT DISTINCT CONVERT(varchar(50), @IntervalStartDateTime, 120), AppName, AVG(App_Mem), COUNT(*)
FROM #MemoryAppStaging
GROUP BY AppName

DROP TABLE #MemoryAppStaging
END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(max)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(max)
SET @ErrorInd = 0
SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

-- report error if any
IF (@ErrorInd = 1)
BEGIN
DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 0
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
END
GO
IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryGroom')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryGroom AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryGroom
@DatasetId uniqueidentifier
,@AggregationTypeId tinyint
,@TableGuid uniqueidentifier
,@CutoffDateTime datetime
,@MaxRowsToGroom int
,@RowsDeleted int OUTPUT
AS
BEGIN
SET NOCOUNT ON

DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(4000)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(4000)

SET @ErrorInd = 0

DECLARE
@Statement nvarchar(max)


BEGIN TRY
IF @AggregationTypeId = 0
BEGIN
SET @Statement = 'DELETE TOP (' + CAST(@MaxRowsToGroom AS varchar(15)) + ')'
+ ' FROM Win10.vWin10MemoryHealthRaw'
+ ' WHERE ([DateTime] &lt; CONVERT(datetime, ''' + CONVERT(varchar(50), @CutoffDateTime, 120) + ''', 120))'

EXECUTE (@Statement)
SET @RowsDeleted = @@ROWCOUNT

SET @Statement = 'DELETE TOP (' + CAST(@MaxRowsToGroom AS varchar(15)) + ')'
+ ' FROM Win10.vWin10MemoryFailureRaw'
+ ' WHERE ([DateTime] &lt; CONVERT(datetime, ''' + CONVERT(varchar(50), @CutoffDateTime, 120) + ''', 120))'

SET @RowsDeleted = @@ROWCOUNT + @RowsDeleted
EXECUTE (@Statement)
END
IF @AggregationTypeId = 30
BEGIN
SET @Statement = 'DELETE FROM Win10.vWin10MemoryHealthAggregationRAM'
+ ' WHERE ([DateTime] &lt; CONVERT(datetime, ''' + CONVERT(varchar(50), @CutoffDateTime, 120) + ''', 120))'
EXECUTE(@Statement)

SET @RowsDeleted = @@ROWCOUNT

SET @Statement = 'DELETE FROM Win10.vWin10MemoryHealthAggregationComputer'
+ ' WHERE ([DateTime] &lt; CONVERT(datetime, ''' + CONVERT(varchar(50), @CutoffDateTime, 120) + ''', 120))'
EXECUTE(@Statement)

SET @RowsDeleted = @@ROWCOUNT + @RowsDeleted

SET @Statement = 'DELETE FROM Win10.vWin10MemoryHealthAggregationApp'
+ ' WHERE ([DateTime] &lt; CONVERT(datetime, ''' + CONVERT(varchar(50), @CutoffDateTime, 120) + ''', 120))'
EXECUTE(@Statement)

SET @RowsDeleted = @@ROWCOUNT + @RowsDeleted
END
END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

-- report error if any
IF (@ErrorInd = 1)
BEGIN


DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, 1
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END

RETURN @RowsDeleted
END
GO


IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryFailureInsert')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryFailureInsert AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryFailureInsert
@ManagementGroupId uniqueidentifier
,@DatasetId uniqueidentifier
,@DataXml ntext
AS
BEGIN
SET NOCOUNT ON


DECLARE @CheckExecResult int
,@ManagementGroupRowId int

SELECT @ManagementGroupRowId = ManagementGroupRowId
FROM vManagementGroup
WHERE (ManagementGroupGuid = @ManagementGroupId) AND (WriterLoginName = SUSER_Name())

EXEC @CheckExecResult = ManagementGroupAccessCheck @ManagementGroupId, @ManagementGroupRowId OUTPUT
IF(@CheckExecResult &lt;&gt; 0) RETURN @CheckExecResult

DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(max)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(max)
SET @ErrorInd = 0

DECLARE
@ExecResult int
,@XmlDocHandle int
,@ResultingState int
SET @ResultingState = 1

BEGIN TRY


EXEC @ExecResult = sp_xml_preparedocument @XmlDocHandle OUTPUT, @DataXml
IF @ExecResult &lt;&gt; 0 RAISERROR(777971000, 16, 1, 'Memory', @ExecResult)

DECLARE
@PrincipalName nvarchar(256)
,@PublisherName nvarchar(256)
,@EventId int
,@RowId int

DECLARE @events TABLE (RowId int IDENTITY(1,1), EventId int, PrincipalName nvarchar(256), PublisherName nvarchar(256))

INSERT INTO @events
SELECT xml.EventId, xml.PrincipalName, xml.PublisherName
FROM OPENXML(@XmlDocHandle, 'Root/Item', 2) WITH (
EventId int
,PrincipalName nvarchar(256)
,PublisherName nvarchar(256)
) xml

WHILE EXISTS (SELECT * FROM @events)
BEGIN
SELECT @RowId = RowId, @EventId = EventId, @PrincipalName = PrincipalName, @PublisherName = PublisherName
FROM @events
WHERE RowId = (SELECT MAX(RowId) FROM @events)

DECLARE
@RAMGuid uniqueidentifier
,@PrincipalNameGuid uniqueidentifier
,@CompManufacturerGuid uniqueidentifier
,@CompModelGuid uniqueidentifier

SELECT @PrincipalNameGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'PrincipalName'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Computer'

SELECT @CompManufacturerGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'Manufacturer'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

SELECT @CompModelGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'Model'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

SELECT @RAMGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'RAM'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

DECLARE @RAM int
,@CompManufacturer nvarchar(256)
,@CompModel nvarchar(256)
,@CompRowId int

SELECT @CompRowId = ManagedEntityRowId
FROM vManagedEntity
WHERE vManagedEntity.Name = @PrincipalName


SELECT @CompManufacturer = CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@CompManufacturerGuid")])'))
,@CompModel = CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@CompModelGuid")])'))
,@RAM = CONVERT(bigint, CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@RAMGuid")])')))/1000000
FROM vManagedEntityProperty
WHERE ManagedEntityRowId = @CompRowId

IF @RAM &gt; 0 AND (@CompManufacturer &lt;&gt; '' OR @CompModel &lt;&gt; '')
BEGIN
SET @RAM = (@RAM - (@RAM % 128)) + (@RAM % 128) / 64 * 128

DECLARE @EventDataRowId int
,@ComputerDataRowId int

IF NOT EXISTS (SELECT * FROM Win10.ComputerData WHERE Manufacturer = @CompManufacturer AND Model = @CompModel)
BEGIN
INSERT INTO Win10.ComputerData (Manufacturer, Model) VALUES (@CompManufacturer, @CompModel)
END

IF NOT EXISTS (SELECT * FROM Win10.EventData WHERE EventId = @EventId AND PublisherName = @PublisherName)
BEGIN
INSERT INTO Win10.EventData (EventId, PublisherName) VALUES (@EventId, @PublisherName)
END

SELECT @EventDataRowId = EventDataRowId FROM Win10.EventData WHERE EventId = @EventId AND PublisherName = @PublisherName
SELECT @ComputerDataRowId = ComputerDataRowId FROM Win10.ComputerData WHERE Manufacturer = @CompManufacturer AND Model = @CompModel

INSERT INTO Win10.vWin10MemoryFailureRaw (DateTime, EventDataRowId, ComputerDataRowId, PrincipalName, RAM) VALUES (GETUTCDATE(), @EventDataRowId, @ComputerDataRowId, @PrincipalName, @RAM)
END

DELETE FROM @events WHERE RowId = @RowId
END

SET @ResultingState = 10
EXEC StandardDatasetMaintenance @DatasetId
END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

IF (@XmlDocHandle IS NOT NULL)
EXEC sp_xml_removedocument @XmlDocHandle

-- report error if any
IF (@ErrorInd = 1)
BEGIN
DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, @ResultingState
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
END
GO

GRANT EXECUTE ON Win10MemoryFailureInsert TO OpsMgrWriter
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryHealthInsert')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryHealthInsert AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryHealthInsert
@ManagementGroupId uniqueidentifier
,@DatasetId uniqueidentifier
,@DataXml ntext
AS
BEGIN
SET NOCOUNT ON


DECLARE @CheckExecResult int
,@ManagementGroupRowId int

SELECT @ManagementGroupRowId = ManagementGroupRowId
FROM vManagementGroup
WHERE (ManagementGroupGuid = @ManagementGroupId) AND (WriterLoginName = SUSER_Name())

EXEC @CheckExecResult = ManagementGroupAccessCheck @ManagementGroupId, @ManagementGroupRowId OUTPUT
IF(@CheckExecResult &lt;&gt; 0) RETURN @CheckExecResult

DECLARE
@ErrorInd bit
,@ErrorMessage nvarchar(max)
,@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorLine int
,@ErrorProcedure nvarchar(256)
,@ErrorMessageText nvarchar(max)
SET @ErrorInd = 0

DECLARE
@ExecResult int
,@XmlDocHandle int
,@ResultingState int
SET @ResultingState = 1

BEGIN TRY


EXEC @ExecResult = sp_xml_preparedocument @XmlDocHandle OUTPUT, @DataXml
IF @ExecResult &lt;&gt; 0 RAISERROR(777971000, 16, 1, 'Memory', @ExecResult)

DECLARE
@PrincipalName nvarchar(256)
,@PublisherName nvarchar(256)
,@EventId int
,@App1 nvarchar(256)
,@App2 nvarchar(256)
,@App3 nvarchar(256)
,@App1_Mem bigint
,@App2_Mem bigint
,@App3_Mem bigint
,@Details xml
,@RowId int

DECLARE @events TABLE (RowId int IDENTITY(1,1), EventId int, PrincipalName nvarchar(256), PublisherName nvarchar(256), Details xml)

INSERT INTO @events
SELECT xml.EventId, xml.PrincipalName, xml.PublisherName, xml.Details
FROM OPENXML(@XmlDocHandle, 'Root/Item', 2) WITH (
EventId int
,PrincipalName nvarchar(256)
,PublisherName nvarchar(256)
,Details xml
) xml

WHILE EXISTS (SELECT * FROM @events)
BEGIN
SELECT @RowId = RowId, @EventId = EventId, @PrincipalName = PrincipalName, @PublisherName = PublisherName, @Details = Details
FROM @events
WHERE RowId = (SELECT MAX(RowId) FROM @events)

SET @App1 = CONVERT(nvarchar(256), @Details.query('declare namespace RADAR="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events";data(/Details/RADAR:MemoryExhaustionInfo/RADAR:ProcessInfo/RADAR:Process_1/RADAR:Name)'))
SET @App2 = CONVERT(nvarchar(256), @Details.query('declare namespace RADAR="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events";data(/Details/RADAR:MemoryExhaustionInfo/RADAR:ProcessInfo/RADAR:Process_2/RADAR:Name)'))
SET @App3 = CONVERT(nvarchar(256), @Details.query('declare namespace RADAR="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events";data(/Details/RADAR:MemoryExhaustionInfo/RADAR:ProcessInfo/RADAR:Process_3/RADAR:Name)'))
SET @App1_Mem = CONVERT(bigint, CONVERT(nvarchar(256), @Details.query('declare namespace RADAR="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events";data(/Details/RADAR:MemoryExhaustionInfo/RADAR:ProcessInfo/RADAR:Process_1/RADAR:CommitCharge)')))/1000000
SET @App2_Mem = CONVERT(bigint, CONVERT(nvarchar(256), @Details.query('declare namespace RADAR="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events";data(/Details/RADAR:MemoryExhaustionInfo/RADAR:ProcessInfo/RADAR:Process_2/RADAR:CommitCharge)')))/1000000
SET @App3_Mem = CONVERT(bigint, CONVERT(nvarchar(256), @Details.query('declare namespace RADAR="http://www.microsoft.com/Windows/Resource/Exhaustion/Detector/Events";data(/Details/RADAR:MemoryExhaustionInfo/RADAR:ProcessInfo/RADAR:Process_3/RADAR:CommitCharge)')))/1000000

DECLARE
@RAMGuid uniqueidentifier
,@PrincipalNameGuid uniqueidentifier
,@CompManufacturerGuid uniqueidentifier
,@CompModelGuid uniqueidentifier

SELECT @PrincipalNameGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'PrincipalName'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Computer'

SELECT @CompManufacturerGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'Manufacturer'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

SELECT @CompModelGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'Model'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

SELECT @RAMGuid = vManagedEntityTypeProperty.PropertyGuid
FROM vManagedEntityTypeProperty
JOIN vManagedEntityType ON (vManagedEntityType.ManagedEntityTypeRowId = vManagedEntityTypeProperty.ManagedEntityTypeRowId)
WHERE vManagedEntityTypeProperty.PropertySystemName = 'RAM'
AND vManagedEntityType.ManagedEntityTypeSystemName = 'Microsoft.Windows.Client.Win10.Aggregate.Computer'

DECLARE @RAM int
,@CompManufacturer nvarchar(256)
,@CompModel nvarchar(256)
,@CompRowId int

SELECT @CompRowId = ManagedEntityRowId
FROM vManagedEntity
WHERE vManagedEntity.Name = @PrincipalName

SELECT @CompManufacturer = CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@CompManufacturerGuid")])'))
,@CompModel = CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@CompModelGuid")])'))
,@RAM = CONVERT(bigint, CONVERT(nvarchar(256), vManagedEntityProperty.PropertyXml.query('data(/Root/Property[@Guid = sql:variable("@RAMGuid")])')))/1000000
FROM vManagedEntityProperty
WHERE ManagedEntityRowId = @CompRowId

IF @RAM &gt; 0 AND (@CompManufacturer &lt;&gt; '' OR @CompModel &lt;&gt; '')
BEGIN

SET @RAM = (@RAM - (@RAM % 128)) + (@RAM % 128) / 64 * 128

DECLARE @EventDataRowId int
,@ComputerDataRowId int

IF NOT EXISTS (SELECT * FROM Win10.ComputerData WHERE Manufacturer = @CompManufacturer AND Model = @CompModel)
BEGIN
INSERT INTO Win10.ComputerData (Manufacturer, Model) VALUES (@CompManufacturer, @CompModel)
END

IF NOT EXISTS (SELECT * FROM Win10.EventData WHERE EventId = @EventId AND PublisherName = @PublisherName)
BEGIN
INSERT INTO Win10.EventData (EventId, PublisherName) VALUES (@EventId, @PublisherName)
END

SELECT @EventDataRowId = EventDataRowId FROM Win10.EventData WHERE EventId = @EventId AND PublisherName = @PublisherName
SELECT @ComputerDataRowId = ComputerDataRowId FROM Win10.ComputerData WHERE Manufacturer = @CompManufacturer AND Model = @CompModel

INSERT INTO Win10.vWin10MemoryHealthRaw (DateTime, EventDataRowId, ComputerDataRowId, PrincipalName, RAM, App1, App2, App3, App1_Mem, App2_Mem, App3_Mem) VALUES (GETUTCDATE(), @EventDataRowId, @ComputerDataRowId, @PrincipalName, @RAM, @App1, @App2, @App3, @App1_Mem, @App2_Mem, @App3_Mem)
END

DELETE FROM @events WHERE RowId = @RowId
END

SET @ResultingState = 10
EXEC StandardDatasetMaintenance @DatasetId
END TRY
BEGIN CATCH
IF (@@TRANCOUNT &gt; 0)
ROLLBACK TRAN

SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()
,@ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-')
,@ErrorMessageText = ERROR_MESSAGE()

SET @ErrorInd = 1
END CATCH

IF (@XmlDocHandle IS NOT NULL)
EXEC sp_xml_removedocument @XmlDocHandle

-- report error if any
IF (@ErrorInd = 1)
BEGIN
DECLARE @AdjustedErrorSeverity int

SET @AdjustedErrorSeverity = CASE
WHEN @ErrorSeverity &gt; 18 THEN 18
ELSE @ErrorSeverity
END

RAISERROR (777971002, @AdjustedErrorSeverity, @ResultingState
,@ErrorNumber
,@ErrorSeverity
,@ErrorState
,@ErrorProcedure
,@ErrorLine
,@ErrorMessageText
)
END
END
GO

GRANT EXECUTE ON Win10MemoryHealthInsert TO OpsMgrWriter
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryRAMReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryRAMReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryRAMReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @RAMAmounts TABLE (RAM bigint)
DECLARE @Weeks TABLE (ListedWeek datetime)
DECLARE @ExhaustionMatrix TABLE (WeekAggregated datetime, Type nvarchar(256), AvgIssues float)

DECLARE @RAMAmount bigint
,@Week datetime
,@AvgIssues float
,@WeekCounter int
,@CurTime datetime

SET @CurTime = CURRENT_TIMESTAMP
DECLARE @MaxSeries int
SET @MaxSeries = 10

SET ROWCOUNT @MaxSeries
DECLARE @series TABLE (series int, NumIssues int)
INSERT INTO @series SELECT RAM, SUM(NumComputers)
FROM Win10.vWin10MemoryHealthAggregationRAM
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 91
GROUP BY RAM
ORDER BY SUM(CONVERT(float, NumEvents)/CONVERT(float, NumComputers)) DESC
SET ROWCOUNT 0

INSERT INTO @RAMAmounts SELECT DISTINCT RAM
FROM Win10.vWin10MemoryHealthAggregationRAM
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 91
AND EXISTS (SELECT * FROM @series AS SeriesList WHERE SeriesList.series = Win10.vWin10MemoryHealthAggregationRAM.RAM)


SET @WeekCounter = -1
WHILE @WeekCounter &gt; -14
BEGIN
INSERT INTO @Weeks VALUES (DATEADD(week, @WeekCounter, @CurTime))
SET @WeekCounter = @WeekCounter - 1
END

SELECT @RAMAmount = MIN(RAM) FROM @RAMAmounts
WHILE @RAMAmount IS NOT NULL
BEGIN
SELECT @Week = MIN(ListedWeek) FROM @Weeks
WHILE @Week IS NOT NULL
BEGIN
SELECT @AvgIssues = SUM(CONVERT(float, NumEvents)/CONVERT(float, NumComputers))
FROM Win10.vWin10MemoryHealthAggregationRAM
WHERE (RAM = @RAMAmount)
AND DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), @Week), DateTime) &lt;= 7
AND DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), @Week), DateTime) &gt; 0
IF @AvgIssues IS NULL
BEGIN
SET @AvgIssues = 0
END
INSERT INTO @ExhaustionMatrix VALUES (DATEADD(week, 1, @Week), CONVERT(nvarchar(256), @RAMAmount), @AvgIssues)

SELECT @Week = MIN(ListedWeek) FROM @Weeks WHERE ListedWeek &gt; @Week
END
SELECT @RAMAmount = MIN(RAM) FROM @RAMAmounts WHERE RAM &gt; @RAMAmount
END

SELECT * FROM @ExhaustionMatrix ORDER BY Type ASC

END
GO

GRANT EXECUTE ON dbo.Win10MemoryRAMReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryMachineReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryMachineReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryMachineReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @MachineTypes TABLE (MachineType nvarchar(256))
DECLARE @Weeks TABLE (ListedWeek datetime)
DECLARE @ExhaustionMatrix TABLE (WeekAggregated datetime, Type nvarchar(256), AvgIssues float)

DECLARE @MachineType nvarchar(256)
,@Week datetime
,@AvgIssues float
,@WeekCounter int
,@CurTime datetime

SET @CurTime = CURRENT_TIMESTAMP
DECLARE @MaxSeries int
SET @MaxSeries = 10

SET ROWCOUNT @MaxSeries
DECLARE @series TABLE (series int, NumIssues int)
INSERT INTO @series SELECT ComputerDataRowId, SUM(NumComputers)
FROM Win10.vWin10MemoryHealthAggregationComputer
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 91
GROUP BY ComputerDataRowId
ORDER BY SUM(CONVERT(float, NumEvents)/CONVERT(float, NumComputers)) DESC
SET ROWCOUNT 0

INSERT INTO @MachineTypes SELECT DISTINCT (Manufacturer + ' ' + Model)
FROM Win10.vWin10MemoryHealthAggregationComputer
JOIN Win10.ComputerData ON (Win10.vWin10MemoryHealthAggregationComputer.ComputerDataRowId = Win10.ComputerData.ComputerDataRowId)
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 91
AND EXISTS (SELECT * FROM @series AS SeriesList WHERE SeriesList.series = Win10.vWin10MemoryHealthAggregationComputer.ComputerDataRowId)

SET @WeekCounter = -1
WHILE @WeekCounter &gt; -14
BEGIN
INSERT INTO @Weeks VALUES (DATEADD(week, @WeekCounter, @CurTime))
SET @WeekCounter = @WeekCounter - 1
END

SELECT @MachineType = MIN(MachineType) FROM @MachineTypes
WHILE @MachineType IS NOT NULL
BEGIN
SELECT @Week = MIN(ListedWeek) FROM @Weeks
WHILE @Week IS NOT NULL
BEGIN
SELECT @AvgIssues = SUM(CONVERT(float, NumEvents)/CONVERT(float, NumComputers))
FROM Win10.vWin10MemoryHealthAggregationComputer
JOIN Win10.ComputerData ON (Win10.vWin10MemoryHealthAggregationComputer.ComputerDataRowId = Win10.ComputerData.ComputerDataRowId)
WHERE ((Manufacturer + ' ' + Model) = @MachineType)
AND DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), @Week), DateTime) &lt;= 7
AND DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), @Week), DateTime) &gt; 0
IF @AvgIssues IS NULL
BEGIN
SET @AvgIssues = 0
END
INSERT INTO @ExhaustionMatrix VALUES (DATEADD(week, 1, @Week), @MachineType, @AvgIssues)

SELECT @Week = MIN(ListedWeek) FROM @Weeks WHERE ListedWeek &gt; @Week
END
SELECT @MachineType = MIN(MachineType) FROM @MachineTypes WHERE MachineType &gt; @MachineType
END

SELECT * FROM @ExhaustionMatrix ORDER BY Type ASC

END
GO

GRANT EXECUTE ON dbo.Win10MemoryMachineReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemorySufficiencyReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemorySufficiencyReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemorySufficiencyReport
AS
BEGIN
SET NOCOUNT ON

SELECT PrincipalName, Manufacturer + ' ' + Model AS Type, RAM, COUNT(*) AS NumInstances
FROM Win10.vWin10MemoryHealthRaw
JOIN Win10.ComputerData ON (Win10.vWin10MemoryHealthRaw.ComputerDataRowId = Win10.ComputerData.ComputerDataRowId)
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 7
GROUP BY PrincipalName, RAM, Manufacturer + ' ' + Model
ORDER BY COUNT (*) DESC

END
GO

GRANT EXECUTE ON dbo.Win10MemorySufficiencyReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAppMemoryReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryAppMemoryReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryAppMemoryReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @MaxSeries int
SET @MaxSeries = 10

SET ROWCOUNT @MaxSeries

SELECT SUM(AvgApp_Mem*NumInstances)/SUM(NumInstances) AS AvgApp_Mem, AppName
FROM Win10.vWin10MemoryHealthAggregationApp
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 90
GROUP BY AppName
ORDER BY SUM(AvgApp_Mem*NumInstances)/SUM(NumInstances) ASC


SET ROWCOUNT 0
END
GO

GRANT EXECUTE ON dbo.Win10MemoryAppMemoryReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAppFrequencyReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryAppFrequencyReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryAppFrequencyReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @MaxSeries int
SET @MaxSeries = 10

SET ROWCOUNT @MaxSeries

SELECT SUM(NumInstances) AS Instances, AppName
FROM Win10.vWin10MemoryHealthAggregationApp
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 90
GROUP BY AppName
ORDER BY SUM(NumInstances) ASC


SET ROWCOUNT 0

END
GO

GRANT EXECUTE ON dbo.Win10MemoryAppFrequencyReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAppDrilldownReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryAppDrilldownReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryAppDrilldownReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @LatestData TABLE (Events int, Memory int, AppName nvarchar(256))

INSERT INTO @LatestData SELECT Win10.vWin10MemoryHealthAggregationApp.NumInstances, Win10.vWin10MemoryHealthAggregationApp.AvgApp_Mem, Win10.vWin10MemoryHealthAggregationApp.AppName
FROM Win10.vWin10MemoryHealthAggregationApp
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 1

INSERT INTO @LatestData SELECT 0, 0, Win10.vWin10MemoryHealthAggregationApp.AppName
FROM Win10.vWin10MemoryHealthAggregationApp
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 90
AND NOT EXISTS (SELECT * FROM @LatestData AS LatestData WHERE LatestData.AppName = Win10.vWin10MemoryHealthAggregationApp.AppName)
GROUP BY AppName

SELECT Win10.vWin10MemoryHealthAggregationApp.AppName, AVG(LatestData.Events) AS EventsToday, AVG(LatestData.Memory) AS MemoryToday, SUM(Win10.vWin10MemoryHealthAggregationApp.NumInstances)/90 AS AvgEvents, AVG(Win10.vWin10MemoryHealthAggregationApp.AvgApp_Mem) AS AvgMemory
FROM Win10.vWin10MemoryHealthAggregationApp
JOIN @LatestData AS LatestData ON (LatestData.AppName = Win10.vWin10MemoryHealthAggregationApp.AppName)
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 90
GROUP BY Win10.vWin10MemoryHealthAggregationApp.AppName
END
GO

GRANT EXECUTE ON dbo.Win10MemoryAppDrilldownReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10FrequencyRAMReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10FrequencyRAMReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10FrequencyRAMReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @MaxSeries int
SET @MaxSeries = 9

SET ROWCOUNT @MaxSeries
DECLARE @series TABLE (series int, NumIssues int)
INSERT INTO @series SELECT RAM, COUNT(*)
FROM Win10.vWin10MemoryHealthRaw
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 7
GROUP BY RAM
ORDER BY COUNT(*) DESC
SET ROWCOUNT 0

DECLARE @FrequencyTable TABLE (NumExhaustions int, RAM nvarchar(256), PrincipalName nvarchar(256))

INSERT @FrequencyTable (
NumExhaustions
,RAM
,PrincipalName
) SELECT COUNT(*), CONVERT(nvarchar(256), RAM), PrincipalName
FROM Win10.vWin10MemoryHealthRaw
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 7
AND EXISTS (SELECT * FROM @series AS SeriesList WHERE SeriesList.series = Win10.vWin10MemoryHealthRaw.RAM)
GROUP BY RAM, PrincipalName

SELECT RAM AS Type, NumExhaustions, COUNT(PrincipalName) AS NumMachines
FROM @FrequencyTable
GROUP BY RAM, NumExhaustions
ORDER BY NumExhaustions ASC
END
GO

GRANT EXECUTE ON dbo.Win10FrequencyRAMReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10FrequencyMachineReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10FrequencyMachineReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10FrequencyMachineReport
AS
BEGIN
SET NOCOUNT ON

DECLARE @MaxSeries int
SET @MaxSeries = 9

SET ROWCOUNT @MaxSeries
DECLARE @series TABLE (series int, NumIssues int)
INSERT INTO @series SELECT ComputerDataRowId, COUNT(*)
FROM Win10.vWin10MemoryHealthRaw
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 7
GROUP BY ComputerDataRowId
ORDER BY COUNT(*) DESC
SET ROWCOUNT 0

DECLARE @FrequencyTable TABLE (NumExhaustions int, Machine nvarchar(256), PrincipalName nvarchar(256))

INSERT @FrequencyTable (
NumExhaustions
,Machine
,PrincipalName
) SELECT COUNT(*), (Manufacturer + ' ' + Model), PrincipalName
FROM Win10.vWin10MemoryHealthRaw
JOIN Win10.ComputerData ON (Win10.vWin10MemoryHealthRaw.ComputerDataRowId = Win10.ComputerData.ComputerDataRowId)
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 7
AND EXISTS (SELECT * FROM @series AS SeriesList WHERE SeriesList.series = Win10.vWin10MemoryHealthRaw.ComputerDataRowId)
GROUP BY (Manufacturer + ' ' + Model), PrincipalName

SELECT Machine AS Type, NumExhaustions, COUNT(PrincipalName) AS NumMachines
FROM @FrequencyTable
GROUP BY Machine, NumExhaustions
ORDER BY NumExhaustions ASC
END
GO

GRANT EXECUTE ON dbo.Win10FrequencyMachineReport TO OpsMgrReader
GO

IF NOT EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryFailureDrilldownReport')
BEGIN
EXECUTE ('CREATE PROCEDURE dbo.Win10MemoryFailureDrilldownReport AS RETURN 1')
END
GO

ALTER PROCEDURE dbo.Win10MemoryFailureDrilldownReport
AS
BEGIN
SET NOCOUNT ON

SELECT DateTime, PrincipalName, PublisherName, EventId, Manufacturer, Model, RAM
FROM Win10.vWin10MemoryFailureRaw
JOIN Win10.ComputerData ON Win10.vWin10MemoryFailureRaw.ComputerDataRowId = Win10.ComputerData.ComputerDataRowId
JOIN Win10.EventData ON Win10.vWin10MemoryFailureRaw.EventDataRowId = Win10.EventData.EventDataRowId
WHERE DateDiff(day, DATEADD(hour, DATEDIFF(hour, GETUTCDATE(), CURRENT_TIMESTAMP), DateTime), CURRENT_TIMESTAMP) &lt;= 7

END
GO

GRANT EXECUTE ON dbo.Win10MemoryFailureDrilldownReport TO OpsMgrReader
GO
</Install>
<Uninstall/>
<Upgrade> SET NOCOUNT ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10FrequencyMachineReport')
BEGIN
GRANT EXECUTE ON dbo.Win10FrequencyMachineReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10FrequencyRAMReport')
BEGIN
GRANT EXECUTE ON dbo.Win10FrequencyRAMReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAppDrilldownReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemoryAppDrilldownReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAppFrequencyReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemoryAppFrequencyReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryAppMemoryReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemoryAppMemoryReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryFailureDrilldownReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemoryFailureDrilldownReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryMachineReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemoryMachineReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemoryRAMReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemoryRAMReport TO OpsMgrReader
END
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Win10MemorySufficiencyReport')
BEGIN
GRANT EXECUTE ON dbo.Win10MemorySufficiencyReport TO OpsMgrReader
END
GO
</Upgrade>
</DataWarehouseDataSet>